| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.rtf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap08 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// Generating a RTF document | |
| 11: | /// </summary> | |
| 12: | public class Chap0801 | |
| 13: | { | |
| 14: | ||
| 15: | public Chap0801() | |
| 16: | { | |
| 17: | ||
| 18: | Console.WriteLine("Chapter 8 example 1: Hello World"); | |
| 19: | ||
| 20: | // step 1: creation of a document-object | |
| 21: | Document document = new Document(); | |
| 22: | ||
| 23: | try | |
| 24: | { | |
| 25: | ||
| 26: | // step 2: | |
| 27: | // we create a writer that listens to the document | |
| 28: | // and directs a RTF-stream to a file | |
| 29: | ||
| 30: | RtfWriter.GetInstance(document, new FileStream("Chap0801.rtf", FileMode.Create)); | |
| 31: | ||
| 32: | // step 3: we open the document | |
| 33: | document.Open(); | |
| 34: | ||
| 35: | // step 4: we add a paragraph to the document | |
| 36: | document.Add(new Paragraph("Hello World")); | |
| 37: | ||
| 38: | } | |
| 39: | catch(DocumentException de) | |
| 40: | { | |
| 41: | Console.Error.WriteLine(de.Message); | |
| 42: | } | |
| 43: | catch(IOException ioe) | |
| 44: | { | |
| 45: | Console.Error.WriteLine(ioe.Message); | |
| 46: | } | |
| 47: | ||
| 48: | // step 5: we close the document | |
| 49: | document.Close(); | |
| 50: | } | |
| 51: | } | |
| 52: | } |