Package com.lowagie.examples.objects.tables

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

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

/**
* Change the height of a cell (fixed height), disable text wrapping, set a minimum height.
*/
public class CellHeights {

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

    System.out.println("Height");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellHeights.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(2);
      table.setExtendLastRow(true);
      LwgPdfPCell cell;
     
      // wrap / nowrap
      cell = new LwgPdfPCell(new Paragraph("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"));
      table.add("wrap");
      cell.setNoWrap(false);
      table.add(cell);
      table.add("no wrap");
      cell.setNoWrap(true);
      table.add(cell);
     
      // height
      cell = new LwgPdfPCell(new Paragraph("1. blah blah\n2. blah blah blah\n3. blah blah\n4. blah blah blah\n5. blah blah\n6. blah blah blah\n7. blah blah\n8. blah blah blah"));
      table.add("height");
      table.add(cell);
      table.add("fixed height");
      cell.setFixedHeight(50f);
      table.add(cell);
      table.add("minimum height");
      cell = new LwgPdfPCell(new Paragraph("x"));
      cell.setMinimumHeight(50f);
      table.add(cell);
      table.add("extend last row");
      cell = new LwgPdfPCell(new Paragraph("almost no content, but the row is extended"));
      table.add(cell);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

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

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.