Set Column text : Column « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    ColumnText ct = new ColumnText(cb);
    int status = ColumnText.START_COLUMN;
    ct.setSimpleColumn(36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36, 18,
        Element.ALIGN_JUSTIFIED);

    Phrase p = new Phrase("line");
    ct.addText(p);
    float pos = ct.getYLine();
    status = ct.go(true);
    if (!ColumnText.hasMoreText(status)) {
      ct.addText(p);
      ct.setYLine(pos);
      ct.go(false);
    } else {
      document.newPage();
      ct.setText(p);
      ct.setYLine(PageSize.A4.height() - 36);
      ct.go();
    }
    document.close();
  }
}








29.24.Column
29.24.1.Using ColumnText
29.24.2.Create Column With SimpleColumn
29.24.3.ColumnText.NO_MORE_COLUMN
29.24.4.Column Properties
29.24.5.ColumnText.hasMoreText
29.24.6.Set Column text
29.24.7.Regular Columns
29.24.8.Add SimpleColumn to MultiColumnText
29.24.9.Columns Right To Left