| 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 Collections | |
| 11: | /// </summary> | |
| 12: | public class Chap0904 | |
| 13: | { | |
| 14: | public Chap0904() | |
| 15: | { | |
| 16: | ||
| 17: | Console.WriteLine("Chapter 9 example 4: True Type Collections"); | |
| 18: | ||
| 19: | // step 1: creation of a document-object | |
| 20: | Document document = new Document(); | |
| 21: | ||
| 22: | try | |
| 23: | { | |
| 24: | String[] names = BaseFont.EnumerateTTCNames("c:\\winnt\\fonts\\msgothic.ttc"); | |
| 25: | for (int i = 0; i < names.Length; i++) | |
| 26: | { | |
| 27: | Console.WriteLine("font " + i + ": " + names[i]); | |
| 28: | } | |
| 29: | ||
| 30: | // step 2: | |
| 31: | // we create a writer that listens to the document | |
| 32: | // and directs a PDF-stream to a file | |
| 33: | PdfWriter.GetInstance(document, new FileStream("Chap0904.pdf", FileMode.Create)); | |
| 34: | ||
| 35: | // step 3: we open the document | |
| 36: | document.Open(); | |
| 37: | ||
| 38: | // step 4: we add content to the document | |
| 39: | BaseFont bf = BaseFont.CreateFont("c:\\winnt\\fonts\\msgothic.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); | |
| 40: | Console.WriteLine("postscriptname: " + bf.PostscriptFontName); | |
| 41: | Font font = new Font(bf, 16); | |
| 42: | String text1 = "\u5951\u7d04\u8005\u4f4f\u6240\u30e9\u30a4\u30f3\uff11"; | |
| 43: | String text2 = "\u5951\u7d04\u8005\u96fb\u8a71\u756a\u53f7"; | |
| 44: | document.Add(new Paragraph(text1, font)); | |
| 45: | document.Add(new Paragraph(text2, font)); | |
| 46: | } | |
| 47: | catch(DocumentException de) | |
| 48: | { | |
| 49: | Console.Error.WriteLine(de.Message); | |
| 50: | } | |
| 51: | catch(IOException ioe) | |
| 52: | { | |
| 53: | Console.Error.WriteLine(ioe.Message); | |
| 54: | } | |
| 55: | ||
| 56: | // step 5: we close the document | |
| 57: | document.Close(); | |
| 58: | } | |
| 59: | } | |
| 60: | } |