donderdag 23 februari 2012

Soft hyphen in iText

The idea of soft-hyphens are not supported in iText 5.1.3. Soft-hyphens mark the spots where a word can be hyphenated. So when a word contains soft-hyphens and is at the end of the line, the word-processor can break the word and the soft-hyphen is shown at the end of the line.

iTextSharp, which is a fine C# opensource PDF generator, does not support soft hyphens and just shows all soft-hyphens as hyphens in the PDF.
When you do not want any hyphenation, you can replace the soft-hyphen, “\xad” with “” before sending the text to iTextSharp.

But in my case, I wanted to use hyphenation and the soft-hyphen idea, so I changed the code of iTextSharp 5.1.3.
And it was not so complex!  First I added a few codelines in the PdfChunk.cs file. The second thing I needed was a manual hyphenation class which determines what is the best place to hyphenate a word. Ofcourse I used the soft-hyphens to determine that.

Here http://www.godzoeker.nl/_nietweg/iTextSoftHyphen20120223.zip you can download a zip which contains the modified PdfChunk.cs and the original PdfChunk.cs so you can see the differences. And the manual hyphenation class is also included.

Geen opmerkingen:

Een reactie posten