Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:   namespace iTextSharp.tutorial.Chap03
8:   {
9:       /// <summary>
10:       /// Lists
11:       /// </summary>
12:       public class Chap0302
13:       {
14:           public Chap0302()
15:           {
16:               Console.WriteLine("Chapter 3 example 2: Lists");
17:           
18:               // step 1: creation of a document-object
19:               Document document new Document();
20:           
21:               try 
22:               {
23:               
24:                   // step 2:
25:                   // we create a writer that listens to the document
26:                   // and directs a PDF-stream to a file
27:                   PdfWriter.GetInstance(documentnew FileStream("Chap0302.pdf"FileMode.Create));
28:               
29:                   // step 3: we Open the document
30:                   document.Open();
31:               
32:                   // step 4:
33:               
34:                   List list new List(true20);
35:                   list.Add(new ListItem("First line"));
36:                   list.Add(new ListItem("The second line is longer to see what happens once the end of the line is reached. Will it start on a new line?"));
37:                   list.Add(new ListItem("Third line"));
38:                   document.Add(list);
39:               
40:                   document.Add(new Paragraph("some books I really like:"));
41:                   ListItem listItem;
42:                   list new List(true15);
43:                   listItem new ListItem("When Harlie was one"FontFactory.GetFont(FontFactory.TIMES_ROMAN12));
44:                   listItem.Add(new Chunk(" by David Gerrold"FontFactory.GetFont(FontFactory.TIMES_ROMAN11Font.ITALIC)));
45:                   list.Add(listItem);
46:                   listItem new ListItem("The World according to Garp"FontFactory.GetFont(FontFactory.TIMES_ROMAN12));
47:                   listItem.Add(new Chunk(" by John Irving"FontFactory.GetFont(FontFactory.TIMES_ROMAN11Font.ITALIC)));
48:                   list.Add(listItem);
49:                   listItem new ListItem("Decamerone"FontFactory.GetFont(FontFactory.TIMES_ROMAN12));
50:                   listItem.Add(new Chunk(" by Giovanni Boccaccio"FontFactory.GetFont(FontFactory.TIMES_ROMAN11Font.ITALIC)));
51:                   list.Add(listItem);
52:                   document.Add(list);
53:               
54:                   Paragraph paragraph new Paragraph("some movies I really like:");
55:                   list new List(false10);
56:                   list.Add("Wild At Heart");
57:                   list.Add("Casablanca");
58:                   list.Add("When Harry met Sally");
59:                   list.Add("True Romance");
60:                   list.Add("Le mari de la coiffeuse");
61:                   paragraph.Add(list);
62:                   document.Add(paragraph);
63:               
64:                   document.Add(new Paragraph("Some authors I really like:"));
65:                   list new List(false20);
66:                   list.ListSymbol new Chunk("\u2022"FontFactory.GetFont(FontFactory.HELVETICA20Font.BOLD));
67:                   listItem new ListItem("Isaac Asimov");
68:                   list.Add(listItem);
69:                   List sublist;
70:                   sublist new List(true10);
71:                   sublist.ListSymbol new Chunk(""FontFactory.GetFont(FontFactory.HELVETICA8));
72:                   sublist.Add("The Foundation Trilogy");
73:                   sublist.Add("The Complete Robot");
74:                   sublist.Add("Caves of Steel");
75:                   sublist.Add("The Naked Sun");
76:                   list.Add(sublist);
77:                   listItem new ListItem("John Irving");
78:                   list.Add(listItem);
79:                   sublist new List(true10);
80:                   sublist.ListSymbol new Chunk(""FontFactory.GetFont(FontFactory.HELVETICA8));
81:                   sublist.Add("The World according to Garp");
82:                   sublist.Add("Hotel New Hampshire");
83:                   sublist.Add("A prayer for Owen Meany");
84:                   sublist.Add("Widow for a year");
85:                   list.Add(sublist);
86:                   listItem new ListItem("Kurt Vonnegut");
87:                   list.Add(listItem);
88:                   sublist new List(true10);
89:                   sublist.ListSymbol new Chunk(""FontFactory.GetFont(FontFactory.HELVETICA8));
90:                   sublist.Add("Slaughterhouse 5");
91:                   sublist.Add("Welcome to the Monkey House");
92:                   sublist.Add("The great pianola");
93:                   sublist.Add("Galapagos");
94:                   list.Add(sublist);
95:                   document.Add(list);
96:               }
97:               catch(DocumentException de
98:               {
99:                   Console.Error.WriteLine(de.Message);
100:               }
101:               catch(IOException ioe
102:               {
103:                   Console.Error.WriteLine(ioe.Message);
104:               }
105:           
106:               // step 5: we close the document
107:               document.Close();
108:  
109:           }
110:       }
111:   }