/* * This code is free software. It may only be copied or modified * if you include the following copyright notice: * * --> Copyright 2001 by Bruno Lowagie <-- * --> Copyright 2004 by Kazuya Ujihara <-- * * This code is example code of 'iText .NET'. * See http://www.ujihara.jp/iTextdotNET/examples.html * * This code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ using System; using com.lowagie.text; using com.lowagie.text.pdf; using System.IO; using GDI=System.Drawing; public class Chap0403 { public static void Main(String[] args) { Console.WriteLine("Chapter 4 example 3: Chapters and Sections"); // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2: we create a writer that listens to the document PdfWriter writer=PdfWriter.getInstance(document, new FileStream("Chap0403.pdf", FileMode.Create)); // step 3: we open the document document.open(); // step 4: we add content to the document Paragraph title1 = new Paragraph("This is Chapter 1", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, GDI.Color.Blue)); Chapter chapter1 = new Chapter(title1, 2); chapter1.setNumberDepth(0); Paragraph someText = new Paragraph("This is some text"); chapter1.add(someText); Paragraph title11 = new Paragraph("This is Section 1 in Chapter 1", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, GDI.Color.Red)); Section section1 = chapter1.addSection(title11); Paragraph someSectionText = new Paragraph("This is some silly paragraph in a chapter and/or section. It contains some text to test the functionality of Chapters and Section."); section1.add(someSectionText); document.add(chapter1); Paragraph title2 = new Paragraph("This is Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC, GDI.Color.Blue)); Chapter chapter2 = new Chapter(title2, 2); chapter2.setNumberDepth(0); chapter2.add(someText); Paragraph title21 = new Paragraph("This is Section 1 in Chapter 2", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, GDI.Color.Red)); Section section2 = chapter2.addSection(title21); section2.add(someSectionText); chapter2.setBookmarkOpen(false); document.add(chapter2); // step 5: we close the document document.close(); } }