| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | using System.Drawing; | |
| 4: | ||
| 5: | using iTextSharp.text; | |
| 6: | using iTextSharp.text.pdf; | |
| 7: | ||
| 8: | ||
| 9: | namespace iTextSharp.tutorial.Chap05 | |
| 10: | { | |
| 11: | /// <summary> | |
| 12: | /// Incrementing the number of colums is also possible, | |
| 13: | /// but it's a little bit more difficult. | |
| 14: | /// It doesn't work automatically. | |
| 15: | /// You have to use the method addColumns and set the widths of the columns | |
| 16: | /// </summary> | |
| 17: | public class Chap0504 | |
| 18: | { | |
| 19: | public Chap0504() | |
| 20: | { | |
| 21: | Console.WriteLine("Chapter 5 example 4: adding columns"); | |
| 22: | // step 1: creation of a document-object | |
| 23: | Document document = new Document(); | |
| 24: | try | |
| 25: | { | |
| 26: | // step 2: | |
| 27: | // we create a writer that listens to the document | |
| 28: | // and directs a PDF-stream to a file | |
| 29: | PdfWriter.GetInstance(document, new FileStream("Chap0504.pdf", FileMode.Create)); | |
| 30: | // step 3: we open the document | |
| 31: | document.Open(); | |
| 32: | // step 4: we create a table and add it to the document | |
| 33: | Table aTable = new Table(2,2); // 2 rows, 2 columns | |
| 34: | aTable.AutoFillEmptyCells = true; | |
| 35: | aTable.AddCell("0.0"); | |
| 36: | aTable.AddCell("0.1"); | |
| 37: | aTable.AddCell("1.0"); | |
| 38: | aTable.AddCell("1.1"); | |
| 39: | aTable.AddColumns(2); | |
| 40: | float[] f = {1f, 1f, 1f, 1f}; | |
| 41: | aTable.Widths = f; | |
| 42: | aTable.AddCell("2.2", new Point(2,2)); | |
| 43: | aTable.AddCell("3.3", new Point(3,3)); | |
| 44: | aTable.AddCell("2.1", new Point(2,1)); | |
| 45: | aTable.AddCell("1.3", new Point(1,3)); | |
| 46: | aTable.AddCell("5.2", new Point(5,2)); | |
| 47: | aTable.AddCell("6.1", new Point(6,1)); | |
| 48: | aTable.AddCell("5.0", new Point(5,0)); | |
| 49: | document.Add(aTable); | |
| 50: | ||
| 51: | } | |
| 52: | catch(DocumentException de) | |
| 53: | { | |
| 54: | Console.Error.WriteLine(de.Message); | |
| 55: | } | |
| 56: | catch(IOException ioe) | |
| 57: | { | |
| 58: | Console.Error.WriteLine(ioe.Message); | |
| 59: | } | |
| 60: | // step 5: we close the document | |
| 61: | document.Close(); | |
| 62: | ||
| 63: | } | |
| 64: | } | |
| 65: | } |