1: | using System; | |
2: | using System.IO; | |
3: | ||
4: | using iTextSharp.text; | |
5: | using iTextSharp.text.pdf; | |
6: | ||
7: | namespace iTextSharp.tutorial.Chap06 | |
8: | { | |
9: | /// <summary> | |
10: | /// Annotations and images | |
11: | /// If you want a clickable image or you want to add an annotation to an image, | |
12: | /// you have to construct an Annotation-object and add it to the image. | |
13: | /// You don't need to specify a position (you can take 0, 0, 0, 0). | |
14: | /// The position will be internally updated to fit the image: | |
15: | /// </summary> | |
16: | public class Chap0616 | |
17: | { | |
18: | ||
19: | public Chap0616() | |
20: | { | |
21: | ||
22: | Console.WriteLine("Chapter 6 example 16: images and annotations"); | |
23: | ||
24: | // step 1: creation of a document-object | |
25: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
26: | try | |
27: | { | |
28: | // step 2: | |
29: | // we create a writer that listens to the document | |
30: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0616.pdf", FileMode.Create)); | |
31: | // step 3: we open the document | |
32: | document.Open(); | |
33: | // step 4: we add some content | |
34: | Image wmf = Image.GetInstance(new Uri("http://itextsharp.sourceforge.net/examples/harbour.wmf")); | |
35: | wmf.Annotation = new Annotation(0, 0, 0, 0, "http://www.lowagie.com"); | |
36: | wmf.SetAbsolutePosition(100f, 600f); | |
37: | document.Add(wmf); | |
38: | Image gif = Image.GetInstance(new Uri("http://itextsharp.sourceforge.net/examples/vonnegut.gif")); | |
39: | gif.Annotation = new Annotation(0, 0, 0, 0, "Chap0610.pdf", 3); | |
40: | gif.SetAbsolutePosition(100f, 400f); | |
41: | document.Add(gif); | |
42: | Image jpeg = Image.GetInstance(new Uri("http://itextsharp.sourceforge.net/examples/myKids.jpg")); | |
43: | jpeg.Annotation = new Annotation("picture", "These are my children", 0, 0, 0, 0); | |
44: | jpeg.SetAbsolutePosition(100f, 150f); | |
45: | document.Add(jpeg); | |
46: | Image png = Image.GetInstance(new Uri("http://itextsharp.sourceforge.net/examples/hitchcock.png")); | |
47: | png.Annotation = new Annotation(0, 0, 0, 0, "Chap0610.pdf", "test"); | |
48: | png.SetAbsolutePosition(350f, 250f); | |
49: | document.Add(png); | |
50: | } | |
51: | catch (Exception de) | |
52: | { | |
53: | Console.Error.WriteLine(de.StackTrace); | |
54: | } | |
55: | ||
56: | // step 5: we close the document | |
57: | document.Close(); | |
58: | } | |
59: | } | |
60: | } |