-1
 Document doc = new Document(iTextSharp.text.PageSize.LETTER.Rotate(), 10, 10, 5, 5);
            string nazivPDFa = txt_datumFiskalnogIsecka.Text +" "+ txt_nazivKompanije.Text;
            PdfWriter pdf = PdfWriter.GetInstance(doc, new FileStream(nazivPDFa + ".pdf", FileMode.CreateNew));
            doc.Open();

Paragraph klijent = new Paragraph(ispisiKlijenta.Text);

PdfPTable tabelaNK = new PdfPTable(1);
PdfPCell kl = new PdfPCell(new Phrase(klijent));
kl.BorderColor = BaseColor.BLACK;
tabelaNK.AddCell(kl);
doc.Add(tabelaNK);

I have create PDF document with itextSharp and when I fill PDF with some text who is in Serbian, he doesnt show me chars like š,ć,č,đ,ž.

Example: I wrote "nešto" and I get "neto".

I have a lot of thinks at that PDF and it will take forever to give to all elements current culture.

ReadyToWork
  • 81
  • 1
  • 10
  • 1
    Out of curiosity: what is this `CurrentCulture` you are referring to? Is it an attempt to translate the word *encoding*? Is it an existing term? Is it something specific to iTextSharp or .NET? – Bruno Lowagie Sep 02 '14 at 07:39
  • @ReadyToWork, the .Net concept of `CurrentCulture` or localization does not exist from a PDF perspective, you just have "text". Along with that, whatever settings your form has (including fonts) or your local environment have, they don't matter. But as long as you don't do weird things like convert your strings to bytes or serialize them then you should be Unicode-safe. iTextSharp will take your Unicode strings and properly create the appropriate byte sequences. However, to do that, _you_ must, as Bruno said, manually supply a font that has glyphs for characters. I'd recommend Arial Unicode MS – Chris Haas Sep 02 '14 at 13:51
  • I had the same problem and this was the answer: http://stackoverflow.com/questions/33699295/croatian-letters-in-itextsharp – Knez Drvene Klupice Aug 12 '16 at 10:38

1 Answers1

1

You aren't using a font when you create your Paragraph. In that case, the Standard Type 1 font Helvetica will be used and it won't be embedded. As Helvetica only supports a limited set of characters, your glyphs won't appear. This is very well documented in the official documentation. It's a pity you try to run before you've learned how to walk.

Several things can be at play.

  1. First, you need to make sure that the encoding of ispisiKlijenta.Text is correct. For instance, is that string in CP1250 or in Unicode? When you write KlijenT.Add("Tekući račun: " +txt_brRacunaKompanije.Text);, you are writing bad code (at least if you were writing Java) because you introduce special characters in your code that may disappear when the code is compiled or executed using a different environment using a different encoding.
  2. Then, you need to provide a font program that knows how to draw the glyphs you need. For instance: Helvetica doesn't know about CP1250, but arial.ttf does (and so do many other fonts, but you need to check first).
  3. Then, you need to decide how you'll use that font. Will you use embed the font as a simple font, as is done in the EncodingExample where we create this PDF, or will you embed the font as a composite font, as is done in the UnicodeExample where we create this PDF. Both PDFs may look identical to you, but they aren't. The choice you make will have an impact on the design of your application.
  4. Once you've made a decision about the font and once you've create a Font object, e.g. named font, you need to use that object when creating a Paragraph.
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Sorry dude, but I tierd of unsuccessful attempts. I look to your comment and I try it, and default font isnt Helvetica, its Microsoft Sans Serif. For font family I dont know what to set. I only have ofered courier, helvetica, symbol, times_roman, undefined and zapfdingbats. Those examples you give post I dont understand. I found 1250 on rtf "{\\rtf1\\ansi\\ansicpg1250\\deff0\\deflang9242{\\fonttbl{\\f0\\fnil\\fcharset238 Microsoft Sans Serif;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs17\\par\r\n – ReadyToWork Sep 02 '14 at 11:00
  • Why are you trying to reinvent the wheel? Many developers before you have succeeded, just by trying out the examples from the book I wrote: http://tinyurl.com/itextsharpIIA2C11 If you don't understand these examples, maybe you should read the book. None of the fonts you mention (courier, helvetica, symbol,...) support CP1250. You need to provide a font program such as a `.ttf`. The example shows that you can find such a file in the `c:/windows/fonts` directory. A good craftsman doesn't blame his tools! – Bruno Lowagie Sep 02 '14 at 11:49