Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:  
8:   namespace iTextSharp.tutorial.Chap01
9:   {
10:       /// <summary>
11:       /// Chapter 1 example 2: PageSize
12:       /// </summary>
13:       public class Chap0102
14:       {
15:           public Chap0102()
16:           {
17:               Console.WriteLine("Chapter 1 example 2: PageSize");
18:  
19:               // step 1: creation of a document-object
20:               Rectangle pageSize = new Rectangle(144, 720);
21:               pageSize.BackgroundColor = new Color(0xFF, 0xFF, 0xDE);
22:               Document document = new Document(pageSize);
23:           
24:               try 
25:               {
26:               
27:                   // step 2:
28:                   // we create a writer that listens to the document
29:                   // and directs a PDF-stream to a file
30:               
31:                   PdfWriter.GetInstance(document, new FileStream("Chap0102.pdf", FileMode.Create));
32:               
33:                   // step 3: we open the document
34:                   document.Open();
35:               
36:                   // step 4: we Add some paragraphs to the document
37:                   for (int i = 0; i < 5; i++) 
38:                   {
39:                       document.Add(new Paragraph("Hello World"));
40:                   }
41:               
42:               }
43:               catch(DocumentException de) 
44:               {
45:                   Console.Error.WriteLine(de.Message);
46:               }
47:               catch(IOException ioe) 
48:               {
49:                   Console.Error.WriteLine(ioe.Message);
50:               }
51:           
52:               // step 5: we close the document
53:               document.Close();
54:  
55:           }
56:       }
57:   }