Package com.lowagie.examples.objects.tables

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

/*
* $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.LwgElement;
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 alignment of the contents of a PdfPCell.
*/
public class CellAlignment {

  /**
   * Changing the alignment
   *
   * @param args
   *            no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("indentation - alignment");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellAlignment.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(2);
      LwgPdfPCell cell;
      Paragraph p = new Paragraph("Quick brown fox jumps over the lazy dog. Quick brown fox jumps over the lazy dog.");
      table.add("default alignment");
      cell = new LwgPdfPCell(p);
      table.add(cell);
      table.add("centered alignment");
      cell = new LwgPdfPCell(p);
      cell.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
      table.add(cell);
      table.add("right alignment");
      cell = new LwgPdfPCell(p);
      cell.setHorizontalAlignment(LwgElement.ALIGN_RIGHT);
      table.add(cell);
      table.add("justified alignment");
      cell = new LwgPdfPCell(p);
      cell.setHorizontalAlignment(LwgElement.ALIGN_JUSTIFIED);
      table.add(cell);
      table.add("blah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\n");
      table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_BASELINE);
      table.add("baseline");
      table.add("blah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\n");
      table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_BOTTOM);
      table.add("bottom");
      table.add("blah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\n");
      table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_MIDDLE);
      table.add("middle");
      table.add("blah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\nblah\n");
      table.getDefaultCell().setVerticalAlignment(LwgElement.ALIGN_TOP);
      table.add("top");
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
}
TOP

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

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.