| 1: | using System; | |
| 2: | using System.IO; | |
| 3: | using System.Collections; | |
| 4: | ||
| 5: | using iTextSharp.text; | |
| 6: | using iTextSharp.text.pdf; | |
| 7: | ||
| 8: | namespace iTextSharp.tutorial.Chap02 | |
| 9: | { | |
| 10: | /// <summary> | |
| 11: | ///Changing the split character | |
| 12: | /// </summary> | |
| 13: | public class Chap0208: ISplitCharacter | |
| 14: | { | |
| 15: | public void Chap0208_() | |
| 16: | { | |
| 17: | Console.WriteLine("Chapter 2 example 8: split character"); | |
| 18: | ||
| 19: | // step 1: creation of a document-object | |
| 20: | Document document = new Document(); | |
| 21: | ||
| 22: | try | |
| 23: | { | |
| 24: | // step 2: | |
| 25: | // we create a writer that listens to the document | |
| 26: | // and directs a PDF-stream to a file | |
| 27: | PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Chap0208.pdf", FileMode.Create)); | |
| 28: | ||
| 29: | // step 3: we Open the document | |
| 30: | document.Open(); | |
| 31: | ||
| 32: | // step 4: | |
| 33: | // we Add some content | |
| 34: | String text = "Some.text.to.show.the.splitting.action.of.the.interface."; | |
| 35: | Chap0208 split = new Chap0208(); | |
| 36: | Chunk ck = new Chunk(text, FontFactory.GetFont(FontFactory.HELVETICA, 24)); | |
| 37: | Paragraph p = new Paragraph(24, ck); | |
| 38: | document.Add(new Paragraph("Normal split.")); | |
| 39: | document.Add(p); | |
| 40: | ck = new Chunk(text, FontFactory.GetFont(FontFactory.HELVETICA, 24)); | |
| 41: | ||
| 42: | ck.SetSplitCharacter(split); | |
| 43: | ||
| 44: | p = new Paragraph(24, ck); | |
| 45: | document.Add(new Paragraph("The dot '.' is the split character.")); | |
| 46: | document.Add(p); | |
| 47: | ||
| 48: | } | |
| 49: | catch(DocumentException de) | |
| 50: | { | |
| 51: | Console.Error.WriteLine(de.Message); | |
| 52: | } | |
| 53: | catch(IOException ioe) | |
| 54: | { | |
| 55: | Console.Error.WriteLine(ioe.Message); | |
| 56: | } | |
| 57: | ||
| 58: | // step 5: we close the document | |
| 59: | document.Close(); | |
| 60: | } | |
| 61: | ||
| 62: | /** | |
| 63: | * Returns <CODE>true</CODE> if the character can split a line. | |
| 64: | * @param c the character | |
| 65: | * @return <CODE>true</CODE> if the character can split a line | |
| 66: | */ | |
| 67: | // bool IsSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck) | |
| 68: | // { | |
| 69: | // | |
| 70: | // } | |
| 71: | public bool IsSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck) | |
| 72: | { | |
| 73: | return (cc[0] == '.'); | |
| 74: | } | |
| 75: | ||
| 76: | public bool IsSplitCharacter(char c) | |
| 77: | { | |
| 78: | return (c == '.'); | |
| 79: | } | |
| 80: | } | |
| 81: | ||
| 82: | } |