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: | /// Positioning the Image | |
11: | /// alignment | |
12: | /// An image can be aligned, using the method | |
13: | /// </summary> | |
14: | public class Chap0604 | |
15: | { | |
16: | public Chap0604() | |
17: | { | |
18: | Console.WriteLine("Chapter 6 example 4: Alignment of images"); | |
19: | // step 1: creation of a document-object | |
20: | Document document = new Document(); | |
21: | try | |
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.GetInstance(document, new FileStream("Chap0604.pdf", FileMode.Create)); | |
27: | ||
28: | // step 3: we open the document | |
29: | document.Open(); | |
30: | ||
31: | Image gif = Image.GetInstance("vonnegut.gif"); | |
32: | gif.Alignment = Image.RIGHT_ALIGN; | |
33: | Image jpeg = Image.GetInstance("myKids.jpg"); | |
34: | jpeg.Alignment = Image.MIDDLE_ALIGN; | |
35: | Image png = Image.GetInstance("hitchcock.png"); | |
36: | png.Alignment = Image.LEFT_ALIGN; | |
37: | ||
38: | document.Add(gif); | |
39: | document.Add(jpeg); | |
40: | document.Add(png); | |
41: | } | |
42: | catch(DocumentException de) | |
43: | { | |
44: | Console.Error.WriteLine(de.Message); | |
45: | } | |
46: | catch(IOException ioe) | |
47: | { | |
48: | Console.Error.WriteLine(ioe.Message); | |
49: | } | |
50: | // step 5: we close the document | |
51: | document.Close(); | |
52: | } | |
53: | } | |
54: | } |