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