Add text to section : Section « PDF « Java Tutorial






import java.io.FileOutputStream;

import com.lowagie.text.Chapter;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
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();
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();
    Phrase text = new Phrase("this is a test. ");
    Font font = new Font(Font.HELVETICA, 14, Font.BOLD);
    Chapter chapter1 = new Chapter(new Paragraph("This is the title.", font), 1);
    chapter1.add(text);
    Section section1 = chapter1.addSection("Quick", 0);
    section1.add(text);
    section1.add(text);
    section1.add(text);
    document.add(chapter1);
    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