1: | using System; | |
2: | using System.Drawing; | |
3: | using System.IO; | |
4: | ||
5: | using iTextSharp.text; | |
6: | using iTextSharp.text.pdf; | |
7: | ||
8: | namespace iTextSharp.tutorial.Chap05 | |
9: | { | |
10: | /// <summary> | |
11: | /// When you use the 'insertTable' method, the widthpercentage of the table you are inserting is not taken into account. | |
12: | /// If you want the table to take only 80% of the width of the cell (this is the default width percentage), | |
13: | /// you have to wrap the table into a Cell. | |
14: | /// </summary> | |
15: | public class Chap0516 | |
16: | { | |
17: | public Chap0516() | |
18: | { | |
19: | Console.WriteLine("Chapter 5 example 16: nested tables"); | |
20: | // step 1: creation of a document-object | |
21: | Document document = new Document(PageSize.A4.Rotate()); | |
22: | try | |
23: | { | |
24: | // step 2: | |
25: | // we create a writer that listens to the document | |
26: | // and directs a PDF-stream to a file | |
27: | PdfWriter.GetInstance(document, new FileStream("Chap0516.pdf", FileMode.Create)); | |
28: | // step 3: we open the document | |
29: | document.Open(); | |
30: | // step 4: we create a table and add it to the document | |
31: | Table secondTable = new Table(2); | |
32: | secondTable.AddCell("2nd table 0.0"); | |
33: | secondTable.AddCell("2nd table 0.1"); | |
34: | secondTable.AddCell("2nd table 1.0"); | |
35: | secondTable.AddCell("2nd table 1.1"); | |
36: | Cell tableCell = new Cell("This is a nested table"); | |
37: | tableCell.Add(secondTable); | |
38: | ||
39: | Table aTable = new Table(3,3); // 3 rows, 3 columns | |
40: | aTable.AddCell("0.0", new Point(0,0)); | |
41: | aTable.AddCell("0.1", new Point(0,1)); | |
42: | aTable.AddCell("0.2", new Point(0,2)); | |
43: | aTable.AddCell("0.0", new Point(1,0)); | |
44: | aTable.AddCell(tableCell, new Point(1,1)); | |
45: | aTable.AddCell("2.2", new Point(1,2)); | |
46: | aTable.AddCell("2.0", new Point(2,0)); | |
47: | aTable.AddCell("2.1", new Point(2,1)); | |
48: | aTable.AddCell("2.2", new Point(2,2)); | |
49: | document.Add(aTable); | |
50: | } | |
51: | catch(DocumentException de) | |
52: | { | |
53: | Console.Error.WriteLine(de.Message); | |
54: | } | |
55: | catch(IOException ioe) | |
56: | { | |
57: | Console.Error.WriteLine(ioe.Message); | |
58: | } | |
59: | // step 5: we close the document | |
60: | document.Close(); | |
61: | ||
62: | } | |
63: | } | |
64: | } |