Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.pdf;
6:  
7:  
8:   namespace iTextSharp.tutorial.Chap05
9:   {
10:       /// <summary>
11:       /// Some Table parameters
12:       /// The tables in the previous examples weren't very nice. 
13:       /// We can set a lot of table parameters to change the look of the table. 
14:       /// Class Table and class Cell are derived from class Rectangle and we can use a lot of typical rectangle-methods.
15:       /// </summary>
16:       public class Chap0505
17:       {
18:           public Chap0505()
19:           {
20:               Console.WriteLine("Chapter 5 example 5: colspan, rowspan, padding, spacing, colors");
21:               // step 1: creation of a document-object
22:               Document document new Document();
23:               try 
24:               {
25:                   // step 2:
26:                   // we create a writer that listens to the document
27:                   // and directs a PDF-stream to a file
28:                   PdfWriter.GetInstance(documentnew FileStream("Chap0505.pdf"FileMode.Create));
29:                   // step 3: we open the document
30:                   document.Open();
31:                   // step 4: we create a table and add it to the document
32:                   Table table new Table(3);
33:                   table.BorderWidth 1;
34:                   table.BorderColor new Color(00255);
35:                   table.Padding 5;
36:                   table.Spacing 5;
37:                   Cell cell new Cell("header");
38:                   cell.Header true;
39:                   cell.Colspan 3;
40:                   table.AddCell(cell);
41:                   cell new Cell("example cell with colspan 1 and rowspan 2");
42:                   cell.Rowspan 2;
43:                   cell.BorderColor new Color(25500);
44:                   table.AddCell(cell);
45:                   table.AddCell("1.1");
46:                   table.AddCell("2.1");
47:                   table.AddCell("1.2");
48:                   table.AddCell("2.2");
49:                   table.AddCell("cell test1");
50:                   cell new Cell("big cell");
51:                   cell.Rowspan 2;
52:                   cell.Colspan 2;
53:                   cell.BackgroundColor new Color(0xC00xC00xC0);
54:                   table.AddCell(cell);
55:                   table.AddCell("cell test2");
56:                   document.Add(table);
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:   }