Add chapter to Document : Document « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Chapter;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Section;
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("1.pdf"));
    document.open();
    document.add(new Paragraph("this"));
    document.newPage();
    Paragraph hello = new Paragraph("paragraph");
    Chapter universe = new Chapter("To the Universe:", 1);
    Section section;
    section = universe.addSection("World:");
    section.add(hello);
    section = universe.addSection("Sun:");
    section.add(hello);
    section = universe.addSection("Moon:");
    section.add(hello);
    section = universe.addSection("Stars:");
    section.add(hello);
    document.add(universe);
    document.close();
  }
}








29.26.Document
29.26.1.Add chapter to Document