Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.xml;
6:   using iTextSharp.text.pdf;
7:   using iTextSharp.text.html;
8:   using iTextSharp.text.rtf;
9:  
10:   namespace iTextSharp.tutorial.Chap07
11:   {
12:       /// <summary>
13:       /// parse an XML file and generate the corresponding PDF (or HTML). 
14:       /// </summary>
15:       public class Chap0702
16:       {
17:           public Chap0702()
18:           {
19:               Console.WriteLine("Chapter 7 example 2: parsing the result of example 1");
20:           
21:               // step 1: creation of a document-object
22:               Document document new Document();
23:           
24:               try 
25:               {
26:               
27:                   // step 2:
28:                   // we create a writer that listens to the document
29:                   // and directs a XML-stream to a file
30:                   PdfWriter.GetInstance(documentnew FileStream("Chap0702.pdf"FileMode.Create));
31:                   HtmlWriter.GetInstance(document,new FileStream("Chap0702.htm"FileMode.Create));
32:                   RtfWriter.GetInstance(document,new FileStream("Chap0702.rtf"FileMode.Create));
33:                   // step 3: we create a parser
34:                   
35:                   ITextHandler h new ITextHandler(document);
36:               
37:                   // step 4: we parse the document
38:                   h.Parse("Chap0701.xml");
39:  
40:               }
41:               catch (Exception e
42:               {
43:                   Console.Error.WriteLine(e.StackTrace);
44:                   Console.Error.WriteLine(e.Message);
45:               }
46:           }
47:       }
48:   }