1: | using System; | |
2: | using System.IO; | |
3: | ||
4: | using iTextSharp.text; | |
5: | using iTextSharp.text.pdf; | |
6: | ||
7: | ||
8: | namespace iTextSharp.tutorial.Chap03 | |
9: | { | |
10: | /// <summary> | |
11: | /// Annotations:Text,External links,External PDF file,Named action,Application | |
12: | /// </summary> | |
13: | public class Chap0303 | |
14: | { | |
15: | public Chap0303() | |
16: | { | |
17: | Console.WriteLine("Chapter 3 example 3: Annotations"); | |
18: | ||
19: | // step 1: creation of a document-object | |
20: | Document document = new Document(); | |
21: | ||
22: | try | |
23: | { | |
24: | ||
25: | // step 2: | |
26: | // we create a writer that listens to the document | |
27: | // and directs a PDF-stream to a file | |
28: | PdfWriter.GetInstance(document, new FileStream("Chap0303.pdf", FileMode.Create)); | |
29: | ||
30: | // step 3: we Open the document | |
31: | document.Open(); | |
32: | ||
33: | // step 4: | |
34: | ||
35: | List list = new List(true, 20); | |
36: | list.Add(new ListItem("First line")); | |
37: | 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?")); | |
38: | list.Add(new ListItem("Third line")); | |
39: | document.Add(list); | |
40: | ||
41: | document.Add(new Paragraph("some books I really like:")); | |
42: | document.Add(new Annotation("books", "This is really a very short list, I like a lot of books.")); | |
43: | ListItem listItem; | |
44: | list = new List(true, 15); | |
45: | listItem = new ListItem("When Harlie was one", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12)); | |
46: | listItem.Add(new Chunk(" by David Gerrold", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC))); | |
47: | list.Add(listItem); | |
48: | listItem = new ListItem("The World according to Garp", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12)); | |
49: | listItem.Add(new Chunk(" by John Irving", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC))); | |
50: | list.Add(listItem); | |
51: | listItem = new ListItem("Decamerone", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12)); | |
52: | listItem.Add(new Chunk(" by Giovanni Boccaccio", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 11, Font.ITALIC))); | |
53: | list.Add(listItem); | |
54: | document.Add(list); | |
55: | ||
56: | document.Add(new Phrase("Some authors I really like:")); | |
57: | document.Add(new Annotation("authors", "Maybe it's because I wanted to be an writer myself that I wrote iText.")); | |
58: | list = new List(false, 20); | |
59: | list.ListSymbol = new Chunk("*", FontFactory.GetFont(FontFactory.HELVETICA, 20, Font.BOLD)); | |
60: | listItem = new ListItem("Isaac Asimov"); | |
61: | list.Add(listItem); | |
62: | List sublist; | |
63: | sublist = new List(true, 10); | |
64: | sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8)); | |
65: | sublist.Add("The Foundation Trilogy"); | |
66: | sublist.Add("The Complete Robot"); | |
67: | sublist.Add("Caves of Steel"); | |
68: | sublist.Add("The Naked Sun"); | |
69: | list.Add(sublist); | |
70: | listItem = new ListItem("John Irving"); | |
71: | list.Add(listItem); | |
72: | sublist = new List(true, 10); | |
73: | sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8)); | |
74: | sublist.Add("The World according to Garp"); | |
75: | sublist.Add("Hotel New Hampshire"); | |
76: | sublist.Add("A prayer for Owen Meany"); | |
77: | sublist.Add("Widow for a year"); | |
78: | list.Add(sublist); | |
79: | listItem = new ListItem("Kurt Vonnegut"); | |
80: | list.Add(listItem); | |
81: | sublist = new List(true, 10); | |
82: | sublist.ListSymbol = new Chunk("", FontFactory.GetFont(FontFactory.HELVETICA, 8)); | |
83: | sublist.Add("Slaughterhouse 5"); | |
84: | sublist.Add("Welcome to the Monkey House"); | |
85: | sublist.Add("The great pianola"); | |
86: | sublist.Add("Galapagos"); | |
87: | list.Add(sublist); | |
88: | document.Add(list); | |
89: | } | |
90: | catch(DocumentException de) | |
91: | { | |
92: | Console.Error.WriteLine(de.Message); | |
93: | } | |
94: | catch(IOException ioe) | |
95: | { | |
96: | Console.Error.WriteLine(ioe.Message); | |
97: | } | |
98: | ||
99: | // step 5: we close the document | |
100: | document.Close(); | |
101: | ||
102: | } | |
103: | } | |
104: | } |