| 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: | /// changing fontwidths | |
| 11: | /// </summary> | |
| 12: | public class Chap0905 | |
| 13: | { | |
| 14: | public Chap0905() | |
| 15: | { | |
| 16: | ||
| 17: | Console.WriteLine("Chapter 9 example 5: changing fontwidths"); | |
| 18: | ||
| 19: | // step 1: creation of a document-object | |
| 20: | Document document = new Document(PageSize.A4, 50, 50, 50, 50); | |
| 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: | ||
| 28: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0905.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 bf = BaseFont.CreateFont("Helvetica", "winansi", false, false, null, null); | |
| 35: | int[] widths = bf.Widths; | |
| 36: | for (int k = 0; k < widths.Length; ++k) | |
| 37: | { | |
| 38: | if (widths[k] != 0) | |
| 39: | widths[k] = 1000; | |
| 40: | } | |
| 41: | bf.ForceWidthsOutput = true; | |
| 42: | document.Add(new Paragraph("A big text to show Helvetica with fixed width.", new Font(bf))); | |
| 43: | ||
| 44: | } | |
| 45: | catch (Exception de) | |
| 46: | { | |
| 47: | Console.Error.WriteLine(de.StackTrace); | |
| 48: | } | |
| 49: | // step 5: we close the document | |
| 50: | document.Close(); | |
| 51: | } | |
| 52: | } | |
| 53: | } |