Blog

 
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 Chap0603 
13:       {
14:       
15:           public Chap0603() 
16:           {
17:           
18:               Console.WriteLine("Chapter 6 example 3: using a relative path for HTML");
19:           
20:               // step 1: creation of a document-object
21:               Document document new Document();
22:           
23:               try 
24:               {
25:               
26:                   // step 2:
27:                   // we create a writer that listens to the document
28:                   // and directs a PDF-stream to a file
29:               
30:                   PdfWriter.GetInstance(documentnew FileStream("Chap0603.pdf"FileMode.Create));
31:  
32:                   // step 3: we open the document
33:                   document.Open();
34:               
35:                   // step 4: we add content
36:                   Image jpg Image.GetInstance("raf.jpg");
37:                   jpg.ScalePercent(50);
38:                   document.Add(jpg);
39:               
40:               }
41:               catch(DocumentException de
42:               {
43:                   Console.Error.WriteLine(de.Message);
44:               }
45:               catch(IOException ioe
46:               {
47:                   Console.Error.WriteLine(ioe.Message);
48:               }
49:           
50:               // step 5: we close the document
51:               document.Close();
52:           }
53:       }}