Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:   namespace iTextSharp.tutorial.Chap04
8:   {
9:       /// <summary>
10:       /// Chapters and Sections
11:       /// </summary>
12:       public class Chap0403
13:       {
14:           public Chap0403()
15:           {
16:               Console.WriteLine("Chapter 4 example 3: Chapters and Sections");
17:           
18:               // step 1: creation of a document-object
19:               Document document new Document(PageSize.A450505050);
20:               try 
21:               {
22:                   // step 2: we create a writer that listens to the document
23:                   PdfWriter writer=PdfWriter.GetInstance(documentnew FileStream("Chap0403.pdf"FileMode.Create));
24:                   // step 3: we open the document
25:                   document.Open();
26:                   // step 4: we Add content to the document
27:                   Paragraph title1 new Paragraph("This is Chapter 1"FontFactory.GetFont(FontFactory.HELVETICA18Font.BOLDITALICnew Color(00255)));
28:                   Chapter chapter1 new Chapter(title12);
29:                   chapter1.NumberDepth 0;
30:                   Paragraph someText new Paragraph("This is some text");
31:                   chapter1.Add(someText);
32:                   Paragraph title11 new Paragraph("This is Section 1 in Chapter 1"FontFactory.GetFont(FontFactory.HELVETICA16Font.BOLDnew Color(25500)));
33:                   Section section1 chapter1.AddSection(title11);
34:                   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.");
35:                   section1.Add(someSectionText);
36:                   document.Add(chapter1);
37:               
38:                   Paragraph title2 new Paragraph("This is Chapter 2"FontFactory.GetFont(FontFactory.HELVETICA18Font.BOLDITALICnew Color(00255)));
39:                   Chapter chapter2 new Chapter(title22);
40:                   chapter2.NumberDepth 0;
41:                   chapter2.Add(someText);
42:                   Paragraph title21 new Paragraph("This is Section 1 in Chapter 2"FontFactory.GetFont(FontFactory.HELVETICA16Font.BOLDnew Color(25500)));
43:                   Section section2 chapter2.AddSection(title21);
44:                   section2.Add(someSectionText);
45:                   chapter2.BookmarkOpen false;
46:                   document.Add(chapter2);
47:               }
48:               catch(Exception de
49:               {
50:                   Console.Error.WriteLine(de.StackTrace);
51:               }
52:               // step 5: we close the document
53:               document.Close();
54:  
55:           }
56:       }
57:   }