| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | ||
| 4: | using iTextSharp.text; | |
| 5: | using iTextSharp.text.pdf; | |
| 6: | ||
| 7: | namespace iTextSharp.tutorial.Chap02 | |
| 8: | { | |
| 9: | /// <summary> | |
| 10: | /// Propagation of the font style | |
| 11: | /// </summary> | |
| 12: | public class Chap0207 | |
| 13: | { | |
| 14: | public Chap0207() | |
| 15: | { | |
| 16: | Console.WriteLine("Chapter 2 example 7: font propagation"); | |
| 17: | ||
| 18: | // step 1: creation of a document-object | |
| 19: | Document document = new Document(); | |
| 20: | ||
| 21: | try | |
| 22: | { | |
| 23: | ||
| 24: | // step 2: | |
| 25: | // we create a writer that listens to the document | |
| 26: | // and directs a PDF-stream to a file | |
| 27: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0207.pdf", FileMode.Create)); | |
| 28: | ||
| 29: | // step 3: we open the document | |
| 30: | document.Open(); | |
| 31: | ||
| 32: | // step 4: | |
| 33: | // we Add some content | |
| 34: | Phrase myPhrase = new Phrase("Hello 1! ", new Font(Font.TIMES_ROMAN, 8, Font.BOLD)); | |
| 35: | myPhrase.Add(new Phrase("some other font ", new Font(Font.HELVETICA, 8))); | |
| 36: | myPhrase.Add(new Phrase("This is the end of the sentence.\n", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC))); | |
| 37: | document.Add(myPhrase); | |
| 38: | ||
| 39: | myPhrase = new Phrase("Hello 1bis! ", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, Font.BOLD)); | |
| 40: | myPhrase.Add(new Phrase("some other font ", FontFactory.GetFont(FontFactory.HELVETICA, 8))); | |
| 41: | myPhrase.Add(new Phrase("This is the end of the sentence.\n", FontFactory.GetFont(FontFactory.TIMES_ROMAN, 8, Font.ITALIC))); | |
| 42: | document.Add(myPhrase); | |
| 43: | ||
| 44: | Paragraph myParagraph = new Paragraph("Hello 2! ", new Font(Font.TIMES_ROMAN, 8, Font.BOLD)); | |
| 45: | myParagraph.Add(new Paragraph("This is the end of the sentence.", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC))); | |
| 46: | document.Add(myParagraph); | |
| 47: | ||
| 48: | myParagraph = new Paragraph(12); | |
| 49: | myParagraph.Add(new Paragraph("Hello 3! ", new Font(Font.TIMES_ROMAN, 8, Font.BOLD))); | |
| 50: | myParagraph.Add(new Paragraph("This is the end of the sentence.", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC))); | |
| 51: | document.Add(myParagraph); | |
| 52: | ||
| 53: | myPhrase = new Phrase(12); | |
| 54: | myPhrase.Add(new Phrase("Hello 4! ", new Font(Font.TIMES_ROMAN, 8, Font.BOLD))); | |
| 55: | myPhrase.Add(new Phrase("This is the end of the sentence.\n", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC))); | |
| 56: | document.Add(myPhrase); | |
| 57: | } | |
| 58: | catch(DocumentException de) | |
| 59: | { | |
| 60: | Console.Error.WriteLine(de.Message); | |
| 61: | } | |
| 62: | catch(IOException ioe) | |
| 63: | { | |
| 64: | Console.Error.WriteLine(ioe.Message); | |
| 65: | } | |
| 66: | ||
| 67: | // step 5: we close the document | |
| 68: | document.Close(); | |
| 69: | ||
| 70: | } | |
| 71: | } | |
| 72: | } |