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: | ||
10: | /// <summary> | |
11: | /// Positioning the Image: | |
12: | /// Absolute positions | |
13: | /// When generating PDF-files, you can use the method | |
14: | /// public void SetAbsolutePosition(int absoluteX, int absoluteY) | |
15: | /// to place an image at an absolute position on a page. | |
16: | /// </summary> | |
17: | public class Chap0606 | |
18: | { | |
19: | ||
20: | public Chap0606() | |
21: | { | |
22: | ||
23: | Console.WriteLine("Chapter 6 example 6: Absolute Positioning of an Image"); | |
24: | ||
25: | // step 1: creation of a document-object | |
26: | Document document = new Document(); | |
27: | ||
28: | try | |
29: | { | |
30: | ||
31: | // step 2: | |
32: | // we create a writer that listens to the document | |
33: | // and directs a PDF-stream to a file | |
34: | ||
35: | PdfWriter.GetInstance(document, new FileStream("Chap0606.pdf", FileMode.Create)); | |
36: | ||
37: | // step 3: we open the document | |
38: | document.Open(); | |
39: | ||
40: | // step 4: we add content | |
41: | Image png = Image.GetInstance("hitchcock.png"); | |
42: | png.SetAbsolutePosition(171, 250); | |
43: | document.Add(png); | |
44: | png.SetAbsolutePosition(342, 500); | |
45: | document.Add(png); | |
46: | } | |
47: | catch(DocumentException de) | |
48: | { | |
49: | Console.Error.WriteLine(de.Message); | |
50: | } | |
51: | catch(IOException ioe) | |
52: | { | |
53: | Console.Error.WriteLine(ioe.Message); | |
54: | } | |
55: | ||
56: | // step 5: we close the document | |
57: | document.Close(); | |
58: | } | |
59: | } | |
60: | } |