Package com.lowagie.examples.objects.tables.pdfptable

Source Code of com.lowagie.examples.objects.tables.pdfptable.CellEvents

/*
* $Id$
*
* This code is part of the 'iText Tutorial'.
* You can find the complete tutorial at the following address:
* http://itextdocs.lowagie.com/tutorial/
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* itext-questions@lists.sourceforge.net
*/
package com.lowagie.examples.objects.tables.pdfptable;


import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgImage;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.LwgRectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.PdfPCellEvent;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;

/**
* General example using CellEvents.
*/
public class CellEvents implements PdfPCellEvent {

  /**
   * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell,
   *      com.lowagie.text.LwgRectangle, com.lowagie.text.pdf.PdfContentByte[])
   */
  public void cellLayout(LwgPdfPCell cell, LwgRectangle position,
      PdfContentByte[] canvases) {
    PdfContentByte cb = canvases[LwgPdfPTable.TEXTCANVAS];
    cb.moveTo(position.getLeft(), position.getBottom());
    cb.lineTo(position.getRight(), position.getTop());
    cb.stroke();
  }

  /**
   * General example using cell events.
   *
   * @param args
   *            no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("CellEvents");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
    try {
      // step2
      PdfWriter writer = PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.pdfptable.CellEvents.pdf"));
      // step3
      document.open();
      // step4
      CellEvents event = new CellEvents();
      LwgImage im = LwgImage.getInstance("otsoe.jpg");
      im.setRotationDegrees(30);
      LwgPdfPTable table = new LwgPdfPTable(4);
      table.add("text 1");
      LwgPdfPCell cell = new LwgPdfPCell(im, true);
      cell.setCellEvent(event);
      table.add(cell);
      table.add("text 3");
      im.setRotationDegrees(0);
      table.add(im);
      table.setTotalWidth(300);
      PdfContentByte cb = writer.getDirectContent();
      table.writeSelectedRows(0, -1, 50, 600, cb);
      table.setHeaderRows(3);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

Related Classes of com.lowagie.examples.objects.tables.pdfptable.CellEvents

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.