| 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: | /// True Type Fonts (not embedded) | |
| 11: | /// </summary> | |
| 12: | public class Chap0902 | |
| 13: | { | |
| 14: | ||
| 15: | public Chap0902() | |
| 16: | { | |
| 17: | ||
| 18: | Console.WriteLine("Chapter 9 example 2: True Type fonts (not embedded)"); | |
| 19: | ||
| 20: | // step 1: creation of a document-object | |
| 21: | Document document = new Document(); | |
| 22: | ||
| 23: | try | |
| 24: | { | |
| 25: | // step 2: | |
| 26: | // we create a writer that listens to the document | |
| 27: | // and directs a PDF-stream to a file | |
| 28: | PdfWriter.GetInstance(document, new FileStream("Chap0902.pdf",FileMode.Create)); | |
| 29: | ||
| 30: | // step 3: we open the document | |
| 31: | document.Open(); | |
| 32: | ||
| 33: | // step 4: we Add content to the document | |
| 34: | BaseFont bfComic = BaseFont.CreateFont("c:\\winnt\\fonts\\comicbd.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED); | |
| 35: | Console.WriteLine("postscriptname: " + bfComic.PostscriptFontName); | |
| 36: | String[] codePages = bfComic.CodePagesSupported; | |
| 37: | for (int i = 0; i < codePages.Length; i++) | |
| 38: | { | |
| 39: | Console.WriteLine(codePages[i]); | |
| 40: | } | |
| 41: | string[][] names = bfComic.FullFontName; | |
| 42: | for (int k = 0; k < names.Length; ++k) | |
| 43: | { | |
| 44: | if (names[k][0].Equals("3") && names[k][1].Equals("1")) // Microsoft encoding | |
| 45: | Console.WriteLine(names[k][3]); | |
| 46: | } | |
| 47: | ||
| 48: | ||
| 49: | Font font = new Font(bfComic, 12); | |
| 50: | String text1 = "This is the quite popular True Type font 'Comic'."; | |
| 51: | document.Add(new Paragraph(text1, font)); | |
| 52: | } | |
| 53: | catch(DocumentException de) | |
| 54: | { | |
| 55: | Console.Error.WriteLine(de.Message); | |
| 56: | } | |
| 57: | catch(IOException ioe) | |
| 58: | { | |
| 59: | Console.Error.WriteLine(ioe.Message); | |
| 60: | } | |
| 61: | ||
| 62: | // step 5: we close the document | |
| 63: | document.Close(); | |
| 64: | } | |
| 65: | } | |
| 66: | } |