Package com.lowagie.examples.objects.tables

Source Code of com.lowagie.examples.objects.tables.NestedTables

/*
* $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;


import com.lowagie.text.LwgDocument;
import com.lowagie.text.LwgPageSize;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import org.geoforge.demo.GfrFileOutputStream;

/**
* Demonstrates the use of nested tables.
*/
public class NestedTables {

  /**
   * Using nested tables.
   *
   * @param args
   *            no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("Nested Tables");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.NestedTables.pdf"));
      // step3
      document.open();
      // step4
            LwgPdfPTable table = new LwgPdfPTable(4);
            LwgPdfPTable nested1 = new LwgPdfPTable(2);
            nested1.add("1.1");
            nested1.add("1.2");
            LwgPdfPTable nested2 = new LwgPdfPTable(1);
            nested2.add("2.1");
            nested2.add("2.2");
            for (int k = 0; k < 24; ++k) {
                if (k == 1) {
                    table.add(nested1);
                }
                else if (k == 20) {
                    table.add(nested2);
                }
                else {
                    table.add("cell " + k);
                }
            }
            document.add(table);
            // step 5: we close the document
            document.close();
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

Related Classes of com.lowagie.examples.objects.tables.NestedTables

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.