Regular Columns : Column « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.MultiColumnText;
import com.lowagie.text.pdf.PdfWriter;

public class MainClass {
  public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    MultiColumnText mct = new MultiColumnText();
    mct.addRegularColumns(document.left(), document.right(), 10f, 3);
    for (int i = 0; i < 30; i++) {
      mct.addElement(new Paragraph(String.valueOf(i + 1)));
      mct.addElement(newParagraph("noun", Element.ALIGN_CENTER, Font.BOLDITALIC));
      for (int j = 0; j < 4; j++) {
        mct.addElement(newParagraph("Line", Element.ALIGN_LEFT, Font.NORMAL));
      }
      mct.addElement(newParagraph("adverb", Element.ALIGN_LEFT, Font.NORMAL));
      mct.addElement(newParagraph("\n\n", Element.ALIGN_LEFT, Font.NORMAL));
    }
    document.add(mct);
    document.close();
    document.close();
  }
  private static Element newParagraph(String text, int alignment, int type) {
    Font font = FontFactory.getFont(BaseFont.HELVETICA, 10, type);
    Paragraph p = new Paragraph(text, font);
    p.setAlignment(alignment);
    p.setLeading(font.size() * 1.2f);
    return p;
  }

}








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