Add section to chapter : Section « 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.18.Section
29.18.1.Add Paragraph to section
29.18.2.Add section to chapter
29.18.3.Create section from Chapter
29.18.4.Add text to section
29.18.5.Set section Indentation Left