| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap09 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// fontfactory styles | |
| 11: | /// </summary> | |
| 12: | public class Chap09_fontfactory_styles | |
| 13: | { | |
| 14: | public Chap09_fontfactory_styles() | |
| 15: | { | |
| 16: | Console.WriteLine("Chapter 9: class FontFactory and Styles"); | |
| 17: | ||
| 18: | // step 1: creation of a document-object | |
| 19: | Document document = new Document(); | |
| 20: | ||
| 21: | try { | |
| 22: | ||
| 23: | // step 2: | |
| 24: | // we create a writer that listens to the document | |
| 25: | // and directs a PDF-stream to a file | |
| 26: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap09_fontfactory_styles.pdf", FileMode.Create)); | |
| 27: | ||
| 28: | // step 3: we open the document | |
| 29: | document.Open(); | |
| 30: | ||
| 31: | // step 4: | |
| 32: | // we add some content | |
| 33: | FontFactory.Register("c:\\winnt\\fonts\\arial.ttf"); | |
| 34: | FontFactory.Register("c:\\winnt\\fonts\\arialbd.ttf"); | |
| 35: | FontFactory.Register("c:\\winnt\\fonts\\ariali.ttf"); | |
| 36: | FontFactory.Register("c:\\winnt\\fonts\\arialbi.ttf"); | |
| 37: | Phrase myPhrase = new Phrase("This is font family Arial ", FontFactory.GetFont("Arial", 8)); | |
| 38: | myPhrase.Add(new Phrase("italic ", FontFactory.GetFont("Arial", 8, Font.ITALIC))); | |
| 39: | myPhrase.Add(new Phrase("bold ", FontFactory.GetFont("Arial", 8, Font.BOLD))); | |
| 40: | myPhrase.Add(new Phrase("bolditalic", FontFactory.GetFont("Arial", 8, Font.BOLDITALIC))); | |
| 41: | document.Add(myPhrase); | |
| 42: | } | |
| 43: | catch(DocumentException de) | |
| 44: | { | |
| 45: | Console.Error.WriteLine(de.Message); | |
| 46: | } | |
| 47: | catch(IOException ioe) | |
| 48: | { | |
| 49: | Console.Error.WriteLine(ioe.Message); | |
| 50: | } | |
| 51: | ||
| 52: | // step 5: we close the document | |
| 53: | document.Close(); | |
| 54: | } | |
| 55: | } | |
| 56: | } |