iTextSharp and special characters (slovak graphemes)

依然范特西╮ 提交于 2019-12-07 03:44:47

问题


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?


回答1:


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)));
}


来源:https://stackoverflow.com/questions/11950338/itextsharp-and-special-characters-slovak-graphemes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!