2

I am trying to typeset a pdf with iTextSharp library, but I cannot find anywhere how to handle diacritics. Since I found tables of contents of two books about iTextSharp where diacritics has a section, I suppose it is doable. So the question is

How to typeset "ř" ?

In addition, is there some guide or link about this problem?

Thanks in advance.

Trimack
  • 4,153
  • 9
  • 44
  • 70

3 Answers3

4

You're going to need to figure out what the Unicode representation is for your diacritical characters. You can embed Unicode characters into a string literal with \u[unicode value in hex]; e.g.

string s = "\u0159";  // Should be your character

You may also need to choose a font that can represent the characters correctly:

bf = BaseFont.CreateFont(...);
font = new Font(bf, 12);
document.Add(new Paragraph(s, font);
Eric Pohl
  • 2,324
  • 1
  • 21
  • 31
  • 1
    The problem was not exactly on the chosen font, but on the encoding. I didn't notice that previously, however thanks. Btw as far as i know all strings in c# are translated into unicode characters. – Trimack Nov 26 '09 at 14:50
  • True enough. In contrived code examples typically used in answers, we're often hard-coding strings, but in real use, the problem is often getting the encoding right when reading text into a string from an outside source (user input, text file, database, etc.) – Eric Pohl Nov 30 '09 at 13:43
  • 1
    here's the link for Romanian Unicode Diacritics http://en.wikipedia.org/wiki/ISO_8859-2 – Dragos Durlut Jan 17 '11 at 17:34
2

I've tried to implement the answer sugested by glaxaco, but it did not work for me.

I've tried to fill out a pdf form with AcroFields, but the diacritics ţşŢŞăîĂÎ etc. would not apeear. (using Arial font)

In the end I've resorted to stripping the diacritics

Pretty weird because when I introduce them by hand, as in MANUALLY filling in the forms, the diacritics show up just fine.

Hope someone can find a solution to this problem. :(

Community
  • 1
  • 1
Dragos Durlut
  • 8,018
  • 10
  • 47
  • 62
  • 2
    the `CreateFont` method has an overload with encoding => something like this `BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, false);` – Trimack Jan 18 '11 at 12:59
0

Diacritics are simply unicode characters. You will have to embed an unicode font into the PDF. See this thread for Java examples, I assume they will be almost the same in C#

Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140