Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:   namespace iTextSharp.tutorial.Chap04
8:   {
9:       /// <summary>
10:       ///Graphic
11:       /// </summary>
12:       public class Chap0404
13:       {
14:           public Chap0404()
15:           {
16:               Console.WriteLine("Chapter 4 example 4: Simple Graphic");
17:  
18:               // step 1: creation of a document-object
19:               Document document new Document();
20:  
21:               try 
22:               {
23:  
24:                   // step 2:
25:                   // we create a writer that listens to the document
26:                   // and directs a PDF-stream to a file
27:  
28:                   PdfWriter.GetInstance(documentnew FileStream("Chap0404.pdf"FileMode.Create));
29:  
30:                   // step 3: we open the document
31:                   document.Open();
32:  
33:                   // step 4: we add a Graphic to the document
34:                   Graphic grx new Graphic();
35:                   // add a rectangle
36:                   grx.Rectangle(100700100100);
37:                   // add the diagonal
38:                   grx.MoveTo(100700);
39:                   grx.LineTo(200800);
40:                   // stroke the lines
41:                   grx.Stroke();
42:                   document.Add(grx);
43:  
44:               }
45:               catch(DocumentException de
46:               {
47:                   Console.Error.WriteLine(de.Message);
48:               }
49:               catch(IOException ioe
50:               {
51:                   Console.Error.WriteLine(ioe.Message);
52:               }
53:  
54:               // step 5: we close the document
55:               document.Close();
56:  
57:           }
58:       }
59:   }