| 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: | /// Chap02_hyphenation | |
| 11: | /// </summary> | |
| 12: | public class Chap02_hyphenation | |
| 13: | { | |
| 14: | public Chap02_hyphenation() | |
| 15: | { | |
| 16: | Console.WriteLine("Chapter 2: hyphenation"); | |
| 17: | ||
| 18: | // step 1: creation of a document-object | |
| 19: | Document document = new Document(PageSize.A4, 100, 300, 100, 100); | |
| 20: | try { | |
| 21: | // step 2: we create a writer that listens to the document | |
| 22: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap02_hyphenation.pdf",FileMode.Create)); | |
| 23: | // step 3: we open the document | |
| 24: | document.Open(); | |
| 25: | // step 4: we add some content | |
| 26: | String text = "It was the best of times, it was the worst of times, " + | |
| 27: | "it was the age of wisdom, it was the age of foolishness, " + | |
| 28: | "it was the epoch of belief, it was the epoch of incredulity, " + | |
| 29: | "it was the season of Light, it was the season of Darkness, " + | |
| 30: | "it was the spring of hope, it was the winter of despair, " + | |
| 31: | "we had everything before us, we had nothing before us, " + | |
| 32: | "we were all going direct to Heaven, we were all going direct " + | |
| 33: | "the other way\u2014in short, the period was so far like the present " + | |
| 34: | "period, that some of its noisiest authorities insisted on its " + | |
| 35: | "being received, for good or for evil, in the superlative degree " + | |
| 36: | "of comparison only."; | |
| 37: | document.Add(new Paragraph("GB")); | |
| 38: | Chunk ckEN = new Chunk(text); | |
| 39: | HyphenationAuto autoEN = new HyphenationAuto("en", "GB", 2, 2); | |
| 40: | ckEN.SetHyphenation(autoEN); | |
| 41: | Paragraph pEN = new Paragraph(ckEN); | |
| 42: | pEN.SetAlignment(ElementTags.ALIGN_JUSTIFIED); | |
| 43: | document.Add(pEN); | |
| 44: | document.Add(new Paragraph("US")); | |
| 45: | Chunk ckUS = new Chunk(text); | |
| 46: | HyphenationAuto autoUS = new HyphenationAuto("en", "US", 2, 2); | |
| 47: | ckUS.SetHyphenation(autoUS); | |
| 48: | Paragraph pUS = new Paragraph(ckUS); | |
| 49: | pUS.SetAlignment(ElementTags.ALIGN_JUSTIFIED); | |
| 50: | document.Add(pUS); | |
| 51: | } | |
| 52: | catch(Exception de) { | |
| 53: | Console.Error.WriteLine(de.Message); | |
| 54: | } | |
| 55: | // step 5: we close the document | |
| 56: | document.Close(); | |
| 57: | } | |
| 58: | } | |
| 59: | } |