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:       /// Annotations:Text,External links,External PDF file,Named action,Application
11:       /// </summary>
12:       public class Chap0304
13:       {
14:           public Chap0304()
15:           {
16:               Console.WriteLine("Chapter 3 example 4: annotations at absolute positions");
17:           
18:               // step 1: creation of a document-object
19:               Document document new Document(PageSize.A450505050);
20:               try 
21:               {
22:                   // step 2:
23:                   // we create a writer that listens to the document
24:                   PdfWriter writer PdfWriter.GetInstance(documentnew FileStream("Chap0304.pdf"FileMode.Create));
25:                   // step 3: we Open the document
26:                   document.Open();
27:                   // step 4: we Add some content
28:               
29:                   PdfContentByte cb writer.DirectContent;
30:  
31:                   // draw a rectangle
32:                   cb.SetRGBColorStroke(0x000x000xFF);
33:                   cb.Rectangle(100700100100);
34:                   cb.Stroke();
35:                   Annotation annot new Annotation(100f700f200f800f"http://itextsharp.Sourceforge.net");
36:                   document.Add(annot);
37:                   cb.SetRGBColorStroke(0xFF0x000x00);
38:                   cb.Rectangle(200700100100);
39:                   cb.Stroke();
40:                   try 
41:                   {
42:                       document.Add(new Annotation(200f700f300f800fnew Uri("http://itextsharp.Sourceforge.net")));
43:                   }
44:                   catch 
45:                   {
46:                   }
47:                   cb.SetRGBColorStroke(0x000xFF0x00);
48:                   cb.Rectangle(300700100100);
49:                   cb.Stroke();
50:                   document.Add(new Annotation(300f700f400f800f"c:/winnt/notepad.exe"nullnullnull));
51:                   cb.SetRGBColorStroke(0x000x000xFF);
52:                   cb.Rectangle(100500100100);
53:                   cb.Stroke();
54:                   document.Add(new Annotation("annotation""This annotation is placed on an absolute position"100f500f200f600f));
55:                   cb.SetRGBColorStroke(0xFF0x000x00);
56:                   cb.Rectangle(200500100100);
57:                   cb.Stroke();
58:                   document.Add(new Annotation(200f500f300f600f"Chap1102a.pdf""test"));
59:                   cb.SetRGBColorStroke(0x000xFF0x00);
60:                   cb.Rectangle(300500100100);
61:                   cb.Stroke();
62:                   document.Add(new Annotation(300f500f400f600f"Chap1102b.pdf"3));
63:               }
64:               catch (Exception de
65:               {
66:                   Console.WriteLine(de.StackTrace);
67:               }
68:           
69:               // step 5: we close the document
70:               document.Close();
71:  
72:           }
73:       }
74:   }