0

I am trying to create a table in PDF file filled with text with polish characters (ą, ę, ć, ż etc.).

dokument.Open();

BaseFont arial = BaseFont.CreateFont(@"C:\Windows\Fonts\ARIALUNI.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(arial, 9);

(...)

dokument.Add(new iTextSharp.text.Paragraph(" ", font));

(...)

table.AddCell(new Phrase(wyraz, font));

And I get text with correct font (ARIALUNI at this case, but i have tried Arial, Helvetica, Courier, Times...) but without polish characters.

For example: I need a word "wymawiać".

With ARIALUNI i get: "wymawia�"

With other fonts i get: "wymawia"

I also tried other encodings, like CP1250, CP1252, CP1257 with these fonts. What should I do?

sprtnbst
  • 60
  • 1
  • 8
  • Both your data and your document must have the same encoding. Don't use legacy encodings like the ones you mentioned. – milleniumbug Apr 26 '15 at 17:12
  • @milleniumbug - Thank you for your answer, i changed .txt file encoding to Unicode and it works! Thank you very much! – sprtnbst Apr 26 '15 at 17:17
  • 1
    You have an encoding problem. You can find a very elaborate answer to your question here: [Can't get Czech characters while generating a PDF](http://stackoverflow.com/questions/26631815/cant-get-czech-characters-while-generating-a-pdf) – Bruno Lowagie Apr 26 '15 at 18:49

1 Answers1

1

This doesn't look like a font issue, it's an encoding issue.

General rule with working with I/O is "decode all input, encode all output" - this also means you must know which encoding you use in your target file.

If you fail to do that, you may see artefacts like these.

milleniumbug
  • 15,379
  • 3
  • 47
  • 71