Mega Code Archive

 
Categories / Java Tutorial / PDF
 

Create section from Chapter

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);     document.add(chapter1);     document.close();   } }