| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap05 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// Some simple tables | |
| 11: | /// </summary> | |
| 12: | public class Chap0501 | |
| 13: | { | |
| 14: | public Chap0501() | |
| 15: | { | |
| 16: | Console.WriteLine("Chapter 5 example 1: my first table"); | |
| 17: | // step 1: creation of a document-object | |
| 18: | Document document = new Document(); | |
| 19: | try | |
| 20: | { | |
| 21: | // step 2: | |
| 22: | // we create a writer that listens to the document | |
| 23: | // and directs a PDF-stream to a file | |
| 24: | PdfWriter.GetInstance(document, new FileStream("Chap0501.pdf", FileMode.Create)); | |
| 25: | // step 3: we open the document | |
| 26: | document.Open(); | |
| 27: | // step 4: we create a table and add it to the document | |
| 28: | Table aTable = new Table(2,2); // 2 rows, 2 columns | |
| 29: | aTable.AddCell("0.0"); | |
| 30: | aTable.AddCell("0.1"); | |
| 31: | aTable.AddCell("1.0"); | |
| 32: | aTable.AddCell("1.1"); | |
| 33: | document.Add(aTable); | |
| 34: | } | |
| 35: | catch(DocumentException de) | |
| 36: | { | |
| 37: | Console.Error.WriteLine(de.Message); | |
| 38: | } | |
| 39: | catch(IOException ioe) | |
| 40: | { | |
| 41: | Console.Error.WriteLine(ioe.Message); | |
| 42: | } | |
| 43: | // step 5: we close the document | |
| 44: | document.Close(); | |
| 45: | ||
| 46: | } | |
| 47: | } | |
| 48: | } |