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: | /// Getting an instance of an image using a filename | |
11: | /// </summary> | |
12: | public class Chap0602 | |
13: | { | |
14: | ||
15: | public Chap0602() | |
16: | { | |
17: | ||
18: | Console.WriteLine("Chapter 6 example 2: Adding a Wmf, Gif, Jpeg and Png-file using filenames"); | |
19: | ||
20: | // step 1: creation of a document-object | |
21: | Document document = new Document(); | |
22: | ||
23: | try | |
24: | { | |
25: | // step 2: | |
26: | // we create a writer that listens to the document | |
27: | // and directs a PDF-stream to a file | |
28: | PdfWriter.GetInstance(document, new FileStream("Chap0602.pdf", FileMode.Create)); | |
29: | ||
30: | // step 3: we open the document | |
31: | document.Open(); | |
32: | ||
33: | Image gif = Image.GetInstance("vonnegut.gif"); | |
34: | Image jpeg = Image.GetInstance("myKids.jpg"); | |
35: | Image png = Image.GetInstance("hitchcock.png"); | |
36: | ||
37: | document.Add(gif); | |
38: | document.Add(jpeg); | |
39: | document.Add(png); | |
40: | } | |
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: | ||
51: | // step 5: we close the document | |
52: | document.Close(); | |
53: | } | |
54: | } | |
55: | } |