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

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

/*
* $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 java.awt.Color;

import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgFont;
import com.lowagie.text.FontFactory;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;

/**
* Break a large table up into different smaller tables in order to save memory.
*/
public class FragmentTable {
  /**
   * Break a large table up into several smaller tables for memory management purposes.
   *
   * @param args
   *            the number of rows for each table fragment.
   */
  public static void main(String[] args) {
     

    System.out.println("FragmentTable");
    int fragmentsize = 25;
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.pdfptable.FragmentTable.pdf"));
      // step3
      document.open();
      // step4
      LwgFont font = FontFactory.getFont("Helvetica", 8, LwgFont.BOLD,
          Color.BLACK);

      LwgPdfPTable table = new LwgPdfPTable(2);
      table.setWidthPercentage(100f);

      LwgPdfPCell h1 = new LwgPdfPCell(new Paragraph("Header 1", font));
      LwgPdfPCell h2 = new LwgPdfPCell(new Paragraph("Header 2", font));
      table.setHeaderRows(1);
      table.add(h1);
      table.add(h2);
      LwgPdfPCell cell;
      for (int row = 1; row <= 2000; row++) {
        if (row % fragmentsize == fragmentsize - 1) {
          document.add(table);
          table.deleteBodyRows();
          table.setSkipFirstHeader(true);
        }
        cell = new LwgPdfPCell(new Paragraph(String.valueOf(row), font));
        table.add(cell);
        cell = new LwgPdfPCell(
            new Paragraph(
                "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla mauris nibh, ultricies nec, adipiscing eget.",
                font));
        table.add(cell);
      }
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

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

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.