| 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 an URL | |
| 11: | /// </summary> | |
| 12: | public class Chap0601 { | |
| 13: | ||
| 14: | public Chap0601() { | |
| 15: | ||
| 16: | Console.WriteLine("Chapter 6 example 1: Adding a Wmf, Gif, Jpeg and Png-file using urls"); | |
| 17: | ||
| 18: | // step 1: creation of a document-object | |
| 19: | Document document = new Document(); | |
| 20: | ||
| 21: | try { | |
| 22: | // step 2: | |
| 23: | // we create a writer that listens to the document | |
| 24: | // and directs a PDF-stream to a file | |
| 25: | PdfWriter.GetInstance(document, new FileStream("Chap0601.pdf", FileMode.Create)); | |
| 26: | ||
| 27: | // step 3: we open the document | |
| 28: | document.Open(); | |
| 29: | //new Uri("") | |
| 30: | Image wmf = Image.GetInstance("harbour.wmf"); | |
| 31: | Image gif = Image.GetInstance("vonnegut.gif"); | |
| 32: | Image jpeg = Image.GetInstance("myKids.jpg"); | |
| 33: | Image png = Image.GetInstance("hitchcock.png"); | |
| 34: | ||
| 35: | document.Add(wmf); | |
| 36: | document.Add(gif); | |
| 37: | document.Add(jpeg); | |
| 38: | document.Add(png); | |
| 39: | } | |
| 40: | ||
| 41: | catch(DocumentException de) { | |
| 42: | Console.Error.WriteLine(de.Message); | |
| 43: | } | |
| 44: | catch(IOException ioe) { | |
| 45: | Console.Error.WriteLine(ioe.Message); | |
| 46: | } | |
| 47: | ||
| 48: | // step 5: we close the document | |
| 49: | document.Close(); | |
| 50: | } | |
| 51: | } | |
| 52: | } |