| 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: | /// Specifying an encoding | |
| 11: | /// </summary> | |
| 12: | public class Chap0901 | |
| 13: | { | |
| 14: | public Chap0901() | |
| 15: | { | |
| 16: | ||
| 17: | Console.WriteLine("Chapter 9 example 1: Other encodings"); | |
| 18: | ||
| 19: | // step 1: creation of a document-object | |
| 20: | Document document = new Document(); | |
| 21: | ||
| 22: | try | |
| 23: | { | |
| 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("Chap0901.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 helvetica = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); | |
| 35: | Console.WriteLine(helvetica.PostscriptFontName); | |
| 36: | Font font = new Font(helvetica, 12, Font.NORMAL); | |
| 37: | Chunk chunk = new Chunk("Sponsor this example and send me 1\u20ac. These are some special characters: \u0152\u0153\u0160\u0161\u0178\u017D\u0192\u02DC\u2020\u2021\u2030", font); | |
| 38: | document.Add(chunk); | |
| 39: | } | |
| 40: | catch(DocumentException de) | |
| 41: | { | |
| 42: | Console.Error.WriteLine(de.Message); | |
| 43: | } | |
| 44: | catch(IOException ioe) | |
| 45: | { | |
| 46: | Console.Error.WriteLine(ioe.Message); | |
| 47: | } | |
| 48: | ||
| 49: | // step 5: we close the document | |
| 50: | document.Close(); | |
| 51: | } | |
| 52: | } | |
| 53: | } |