| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap10 | |
| 8: | { | |
| 9: | public class Chap1010 | |
| 10: | { | |
| 11: | ||
| 12: | public Chap1010() | |
| 13: | { | |
| 14: | ||
| 15: | Console.WriteLine("Chapter 10 example 10: nested PdfPTables"); | |
| 16: | ||
| 17: | // step 1: creation of a document-object | |
| 18: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
| 19: | try | |
| 20: | { | |
| 21: | // step 2: we create a writer that listens to the document | |
| 22: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap1010.pdf", FileMode.Create)); | |
| 23: | // step 3: we open the document | |
| 24: | document.Open(); | |
| 25: | // step 4: we add some content | |
| 26: | PdfPTable table = new PdfPTable(4); | |
| 27: | PdfPTable nested1 = new PdfPTable(2); | |
| 28: | nested1.AddCell("1.1"); | |
| 29: | nested1.AddCell("1.2"); | |
| 30: | PdfPTable nested2 = new PdfPTable(1); | |
| 31: | nested2.AddCell("2.1"); | |
| 32: | nested2.AddCell("2.2"); | |
| 33: | for (int k = 0; k < 24; ++k) | |
| 34: | { | |
| 35: | if (k == 1) | |
| 36: | { | |
| 37: | table.AddCell(nested1); | |
| 38: | } | |
| 39: | else if (k == 20) | |
| 40: | { | |
| 41: | table.AddCell(nested2); | |
| 42: | } | |
| 43: | else | |
| 44: | { | |
| 45: | table.AddCell("cell " + k); | |
| 46: | } | |
| 47: | } | |
| 48: | table.TotalWidth = 300; | |
| 49: | table.WriteSelectedRows(0, -1, 100, 600, writer.DirectContent); | |
| 50: | // step 5: we close the document | |
| 51: | document.Close(); | |
| 52: | } | |
| 53: | catch (Exception de) | |
| 54: | { | |
| 55: | Console.Error.WriteLine(de.Message); | |
| 56: | Console.Error.WriteLine(de.StackTrace); | |
| 57: | } | |
| 58: | } | |
| 59: | } | |
| 60: | } |