| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | ||
| 8: | namespace iTextSharp.tutorial.Chap05 | |
| 9: | { | |
| 10: | /// <summary> | |
| 11: | /// borders | |
| 12: | /// </summary> | |
| 13: | public class Chap0507 | |
| 14: | { | |
| 15: | public Chap0507() | |
| 16: | { | |
| 17: | Console.WriteLine("Chapter 5 example 7: borders"); | |
| 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("Chap0507.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 table = new Table(3); | |
| 30: | table.BorderWidth = 1; | |
| 31: | table.BorderColor = new Color(0, 0, 255); | |
| 32: | table.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; | |
| 33: | ||
| 34: | table.Padding = 5; | |
| 35: | table.Spacing = 5; | |
| 36: | Cell cell = new Cell("header"); | |
| 37: | cell.Header = true; | |
| 38: | cell.BorderWidth = 3; | |
| 39: | cell.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER; | |
| 40: | cell.Colspan = 3; | |
| 41: | table.AddCell(cell); | |
| 42: | cell = new Cell("example cell with colspan 1 and rowspan 2"); | |
| 43: | cell.Rowspan = 2; | |
| 44: | cell.BorderColor = new Color(255, 0, 0); | |
| 45: | cell.Border = Rectangle.LEFT_BORDER | Rectangle.BOTTOM_BORDER; | |
| 46: | table.AddCell(cell); | |
| 47: | table.AddCell("1.1"); | |
| 48: | table.AddCell("2.1"); | |
| 49: | table.AddCell("1.2"); | |
| 50: | table.AddCell("2.2"); | |
| 51: | table.AddCell("cell test1"); | |
| 52: | cell = new Cell("big cell"); | |
| 53: | cell.Rowspan = 2; | |
| 54: | cell.Colspan = 2; | |
| 55: | cell.Border = Rectangle.NO_BORDER; | |
| 56: | cell.GrayFill = 0.9f; | |
| 57: | table.AddCell(cell); | |
| 58: | table.AddCell("cell test2"); | |
| 59: | document.Add(table); | |
| 60: | } | |
| 61: | catch(DocumentException de) | |
| 62: | { | |
| 63: | Console.Error.WriteLine(de.Message); | |
| 64: | } | |
| 65: | catch(IOException ioe) | |
| 66: | { | |
| 67: | Console.Error.WriteLine(ioe.Message); | |
| 68: | } | |
| 69: | // step 5: we close the document | |
| 70: | document.Close(); | |
| 71: | ||
| 72: | } | |
| 73: | } | |
| 74: | } |