Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:   namespace iTextSharp.tutorial.Chap11
8:   {
9:       public class Chap1101 
10:       {
11:       
12:           public Chap1101() 
13:           {
14:           
15:               Console.WriteLine("Chapter 11 example 1: local goto");
16:           
17:               // step 1: creation of a document-object
18:               Document document new Document();
19:           
20:               try 
21:               {
22:               
23:                   // step 2:
24:                   // we create a writer that listens to the document
25:                   // and directs a PDF-stream to a file
26:                   PdfWriter writer PdfWriter.GetInstance(documentnew FileStream("Chap1101.pdf"FileMode.Create));
27:               
28:                   // step 3: we open the document
29:                   document.Open();
30:               
31:                   // step 4: we add some content
32:               
33:                   Paragraph p1 new Paragraph("We will do something special with this paragraph. If you click on "FontFactory.GetFont(FontFactory.HELVETICA12));
34:                   p1.Add(new Chunk("this word"FontFactory.GetFont(FontFactory.HELVETICA12Font.NORMALnew Color(00255))).SetLocalGoto("test"));
35:                   p1.Add(" you will automatically jump to another location in this document.");
36:                   Paragraph p2 new Paragraph("blah, blah, blah");
37:                   Paragraph p3 new Paragraph("This paragraph contains a local ");
38:                   p3.Add(new Chunk("local destination"FontFactory.GetFont(FontFactory.HELVETICA12Font.NORMALnew Color(02550))).SetLocalDestination("test"));
39:                   document.Add(p1);
40:                   document.Add(p2);
41:                   document.Add(p2);
42:                   document.Add(p2);
43:                   document.Add(p2);
44:                   document.Add(p2);
45:                   document.Add(p2);
46:                   document.Add(p2);
47:                   document.Add(p3);
48:               }
49:               catch(DocumentException de
50:               {
51:                   Console.Error.WriteLine(de.Message);
52:               }
53:               catch(IOException ioe
54:               {
55:                   Console.Error.WriteLine(ioe.Message);
56:               }
57:           
58:               // step 5: we close the document
59:               document.Close();
60:           }
61:       }
62:   }