Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:   namespace iTextSharp.tutorial.Chap05
8:   {
9:       /// <summary>
10:       /// Table splitting
11:       /// </summary>
12:       public class Chap0508
13:       {
14:           public Chap0508()
15:           {
16:               Console.WriteLine("Chapter 5 example 8: table splitting");
17:               // step 1: creation of a document-object
18:               Document document = new Document();
19:               try 
20:               {
21:                   // step 2:
22:                   // we create a writer that listens to the document
23:                   // and directs a PDF-stream to a file
24:                   PdfWriter.GetInstance(document, new FileStream("Chap0508.pdf", FileMode.Create));
25:                   // step 3: we open the document
26:                   document.Open();
27:                   // step 4: we create a table and add it to the document
28:                   Table table = new Table(3);
29:                   table.BorderWidth = 1;
30:                   table.BorderColor = new Color(0, 0, 255);
31:                   table.Padding = 5;
32:                   table.Spacing = 5;
33:                   Cell cell = new Cell("header");
34:                   cell.Header = true;
35:                   cell.Colspan = 3;
36:                   table.AddCell(cell);
37:                   cell = new Cell("example cell with colspan 1 and rowspan 2");
38:                   cell.Rowspan = 2;
39:                   cell.BorderColor = new Color(255, 0, 0);
40:                   table.AddCell(cell);
41:                   table.AddCell("1.1");
42:                   table.AddCell("2.1");
43:                   table.AddCell("1.2");
44:                   table.AddCell("2.2");
45:                   table.AddCell("cell test1");
46:                   cell = new Cell("big cell");
47:                   cell.Rowspan = 2;
48:                   cell.Colspan = 2;
49:                   cell.BackgroundColor = new Color(0xC0, 0xC0, 0xC0);
50:                   table.AddCell(cell);
51:                   table.AddCell("cell test2");
52:                   document.Add(new Paragraph("repeating the same table 10 times:"));
53:                   for (int i = 0; i < 10; i++) 
54:                   {
55:                       document.Add(table);
56:                   }
57:               }
58:               catch(DocumentException de) 
59:               {
60:                   Console.Error.WriteLine(de.Message);
61:               }
62:               catch(IOException ioe) 
63:               {
64:                   Console.Error.WriteLine(ioe.Message);
65:               }
66:               // step 5: we close the document
67:               document.Close();
68:  
69:           }
70:       }
71:   }