Package com.lowagie.examples.objects.tables

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

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

/**
* Define the widths of the columns of a PdfPTable.
*/
public class CellWidths {

  /**
   * Width manipulations of cells.
   *
   * @param args
   *            no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("Width");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4, 36, 36, 36, 36);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellWidths.pdf"));
      // step3
      document.open();
      // step4
      float[] widths = {0.1f, 0.1f, 0.05f, 0.75f};
      LwgPdfPTable table = new LwgPdfPTable(widths);
      table.add("10%");
      table.add("10%");
      table.add("5%");
      table.add("75%");
      table.add("aa");
      table.add("aa");
      table.add("a");
      table.add("aaaaaaaaaaaaaaa");
      table.add("bb");
      table.add("bb");
      table.add("b");
      table.add("bbbbbbbbbbbbbbb");
      table.add("cc");
      table.add("cc");
      table.add("c");
      table.add("ccccccccccccccc");
      document.add(table);
      document.add(new Paragraph("We change the percentages:\n\n"));
      widths[0] = 20f;
      widths[1] = 20f;
      widths[2] = 10f;
      widths[3] = 50f;
      table.setWidths(widths);
      document.add(table);
      widths[0] = 40f;
      widths[1] = 40f;
      widths[2] = 20f;
      widths[3] = 300f;
      LwgRectangle r = new LwgRectangle(LwgPageSize.A4.getRight(72), LwgPageSize.A4.getTop(72));
      table.setWidthPercentage(widths, r);
      document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
      document.add(table);
      document.add(new Paragraph("We use a locked width:\n\n"));
      table.setTotalWidth(300);
      table.setLockedWidth(true);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

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

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.