1: | using System; | |
2: | using System.Drawing; | |
3: | using System.IO; | |
4: | ||
5: | using iTextSharp.text; | |
6: | using iTextSharp.text.pdf; | |
7: | ||
8: | ||
9: | namespace iTextSharp.tutorial.Chap05 | |
10: | { | |
11: | /// <summary> | |
12: | /// When you use the 'insertTable' method, the widthpercentage of the table you are inserting is not taken into account. | |
13: | /// If you want the table to take only 80% of the width of the cell (this is the default width percentage), | |
14: | /// you have to wrap the table into a Cell | |
15: | /// </summary> | |
16: | public class Chap0515 | |
17: | { | |
18: | public Chap0515() | |
19: | { | |
20: | Console.WriteLine("Chapter 5 example 15: nested tables"); | |
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(document, new FileStream("Chap0515.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 secondTable = new Table(2); | |
33: | secondTable.AddCell("2.0.0"); | |
34: | secondTable.AddCell("2.0.1"); | |
35: | secondTable.AddCell("2.1.0"); | |
36: | secondTable.AddCell("2.1.1"); | |
37: | Cell tableCell = new Cell(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: | } |