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:       /// System.Drawing.Bitmap
11:       /// </summary>
12:       public class Chap0610 
13:       {
14:       
15:           public Chap0610() 
16:           {
17:           
18:               Console.WriteLine("Chapter 6 example 10: Images using System.Drawing.Bitmap!");
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:                   PdfWriter writer PdfWriter.GetInstance(documentnew FileStream("Chap0610.pdf"FileMode.Create));
30:               
31:                   // step 3: we open the document
32:                   document.Open();
33:               
34:                   // step 4: we add content to the document
35:                   for (int 0300i++) 
36:                   {
37:                       document.Add(new Phrase("Who is this? "));
38:                   }
39:                   PdfContentByte cb writer.DirectContent;
40:   //                Image image = Image.GetInstance(new System.Drawing.Bitmap("h.gif"), null);
41:                   Image image Image.GetInstance("h.gif");
42:                   image.SetAbsolutePosition(100200);
43:                   cb.AddImage(image);
44:               }
45:               catch(DocumentException de
46:               {
47:                   Console.WriteLine(de.Message);
48:               }
49:               catch(IOException ioe
50:               {
51:                   Console.WriteLine(ioe.Message);
52:               }
53:           
54:               // step 5: we close the document
55:               document.Close();
56:           }
57:       }
58:   }