I am having trouble with some special slovak characters (for example č, ň and ť). They are disappearing in the itextsharp generated pdf.
From what I've been able to find, this problem has to do with encoding of my BaseFont
. Currently I am using this:
BaseFont.CreateFont(BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.CP1250, BaseFont.NOT_EMBEDDED)
Someone suggested that this should work:
BaseFont.CreateFont(BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
But it throws this exception error:
System.ArgumentException was caught
Message='Identity-H' is not a supported encoding name.
Parameter name: name
ParamName=name
Source=mscorlib
Anyone know a possible reason and solution to this?
The problem is here:
BaseFont.CreateFont(BaseFont.HELVETICA ...
BaseFont.HELVETICA
is a standard type 1 font and can't be used for your slovak characters. You need to use a font with the correct glyphs:
string FONT = "c:/windows/fonts/arialbd.ttf";
using (Document document = new Document()) {
PdfWriter.GetInstance(document, STREAM);
document.Open();
BaseFont bf = BaseFont.CreateFont(
FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED
);
document.Add(new Paragraph("č, ň and ť", new Font(bf, 12)));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With