1: | using System; | |
2: | using System.IO; | |
3: | using System.Drawing; | |
4: | ||
5: | using iTextSharp.text; | |
6: | using iTextSharp.text.pdf; | |
7: | ||
8: | namespace iTextSharp.tutorial.Chap05 | |
9: | { | |
10: | /// <summary> | |
11: | /// add cells at a certain position in the table | |
12: | /// </summary> | |
13: | public class Chap0502 | |
14: | { | |
15: | public Chap0502() | |
16: | { | |
17: | Console.WriteLine("Chapter 5 example 2: adding cells at a specific position"); | |
18: | // step 1: creation of a document-object | |
19: | Document document = new Document(); | |
20: | try | |
21: | { | |
22: | // step 2: | |
23: | // we create a writer that listens to the document | |
24: | // and directs a PDF-stream to a file | |
25: | PdfWriter.GetInstance(document, new FileStream("Chap0502.pdf", FileMode.Create)); | |
26: | // step 3: we open the document | |
27: | document.Open(); | |
28: | // step 4: we create a table and add it to the document | |
29: | Table aTable; | |
30: | ||
31: | aTable = new Table(4,4); // 4 rows, 4 columns | |
32: | aTable.AutoFillEmptyCells = true; | |
33: | aTable.AddCell("2.2", new Point(2,2)); | |
34: | aTable.AddCell("3.3", new Point(3,3)); | |
35: | aTable.AddCell("2.1", new Point(2,1)); | |
36: | aTable.AddCell("1.3", new Point(1,3)); | |
37: | document.Add(aTable); | |
38: | document.NewPage(); | |
39: | ||
40: | aTable = new Table(4,4); // 4 rows, 4 columns | |
41: | aTable.AddCell("2.2", new Point(2,2)); | |
42: | aTable.AddCell("3.3", new Point(3,3)); | |
43: | aTable.AddCell("2.1", new Point(2,1)); | |
44: | aTable.AddCell("1.3", new Point(1,3)); | |
45: | document.Add(aTable); | |
46: | } | |
47: | catch(DocumentException de) | |
48: | { | |
49: | Console.Error.WriteLine(de.Message); | |
50: | } | |
51: | catch(IOException ioe) | |
52: | { | |
53: | Console.Error.WriteLine(ioe.Message); | |
54: | } | |
55: | // step 5: we close the document | |
56: | document.Close(); | |
57: | ||
58: | } | |
59: | } | |
60: | } |