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

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

/*
* $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.LwgPageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.LwgRectangle;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;

/**
* Writing a PdfPTable at an absolute position.
*/
public class WriteSelectedRows {

  /**
   * Demonstrates the writeSelectedRows method.
   *
   * @param args
   *            no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("writeSelectedRows");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4, 2, 2, 2, 2);
    try {
      // step2
      PdfWriter writer = PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.pdfptable.WriteSelectedRows.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(4);
            table.getDefaultCell().setBorder(LwgRectangle.LEFT | LwgRectangle.RIGHT);
            for (int k = 0; k < 24; ++k) {
                table.add("cell " + k);
            }
            table.setTotalWidth(300f);
            table.writeSelectedRows(0, -1, 100, 600, writer.getDirectContent());
            document.newPage();
            document.add(table);
            document.newPage();
            table = new LwgPdfPTable(2);
            float[] rows = { 50f, 250f };
            table.setTotalWidth(rows);
            for (int k = 0; k < 200; ++k) {
                table.add("row " + k);
                table.add("blah blah blah " + k);
            }
            document.add(new Paragraph("row 0 - 50"));
            table.writeSelectedRows(0, 50, 50, 820, writer.getDirectContent());
            document.newPage();
            document.add(new Paragraph("row 50 - 100"));
            table.writeSelectedRows(50, 100, 50, 820, writer.getDirectContent());
            document.newPage();
            document.add(new Paragraph("row 100 - 150 DOESN'T FIT ON THE PAGE!!!"));
            table.writeSelectedRows(100, 150, 50, 200, writer.getDirectContent());
            document.newPage();
            document.add(new Paragraph("row 150 - 200"));
            table.writeSelectedRows(150, -1, 50, 820, writer.getDirectContent());
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

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

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.