Blog

 
1:   using System;
2:   using System.IO;
3:   using System.Drawing;
4:  
5:   using iTextSharp.text;
6:   using iTextSharp.text.pdf;
7:  
8:  
9:   namespace iTextSharp.tutorial.Chap05
10:   {
11:       /// <summary>
12:       /// iText automatically adds rows when needed
13:       /// </summary>
14:       public class Chap0503
15:       {
16:           public Chap0503()
17:           {
18:               Console.WriteLine("Chapter 5 example 3: rows added automatically");
19:               // step 1: creation of a document-object
20:               Document document new Document();
21:               try 
22:               {
23:                   // step 2:
24:                   // we create a writer that listens to the document
25:                   // and directs a PDF-stream to a file
26:                   PdfWriter.GetInstance(documentnew FileStream("Chap0503.pdf"FileMode.Create));
27:                   // step 3: we open the document
28:                   document.Open();
29:                   // step 4: we create a table and add it to the document
30:                   Table aTable new Table(4,4);    // 4 rows, 4 columns
31:                   aTable.AutoFillEmptyCells true;
32:                   aTable.AddCell("2.2"new Point(2,2));
33:                   aTable.AddCell("3.3"new Point(3,3));
34:                   aTable.AddCell("2.1"new Point(2,1));
35:                   aTable.AddCell("1.3"new Point(1,3));
36:                   aTable.AddCell("5.2"new Point(5,2));
37:                   aTable.AddCell("6.1"new Point(6,1));
38:                   aTable.AddCell("5.0"new Point(5,0));  
39:                   document.Add(aTable);                      
40:               }
41:               catch(DocumentException de
42:               {
43:                   Console.Error.WriteLine(de.Message);
44:               }
45:               catch(IOException ioe
46:               {
47:                   Console.Error.WriteLine(ioe.Message);
48:               }
49:               // step 5: we close the document
50:               document.Close();
51:  
52:           }
53:       }
54:   }