Blog

 
1:   using System;
2:   using System.IO;
3:  
4:   using iTextSharp.text;
5:   using iTextSharp.text.rtf;
6:  
7:   namespace iTextSharp.tutorial.Chap08
8:   {
9:       /// <summary>
10:       /// Tables and RTF
11:       /// </summary>
12:       public class Chap0804 
13:       {
14:           public  Chap0804() 
15:           {
16:               Console.WriteLine("Chapter 8 example 4: Tables and RTF");
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:                   RtfWriter.GetInstance(documentnew FileStream("Chap0804.rtf"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(00255);
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(25500);
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(0xC00xC00xC0);
50:                   table.AddCell(cell);
51:                   table.AddCell("cell test2");
52:                   document.Add(table);
53:               }
54:               catch(DocumentException de
55:               {
56:                   Console.Error.WriteLine(de.Message);
57:               }
58:               catch(IOException ioe
59:               {
60:                   Console.Error.WriteLine(ioe.Message);
61:               }
62:               // step 5: we close the document
63:               document.Close();
64:           }
65:       }
66:   }