iTextSharp和特殊字符(斯洛伐克字素) [英] iTextSharp and special characters (slovak graphemes)
本文介绍了iTextSharp和特殊字符(斯洛伐克字素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到一些特殊的斯洛伐克人物(例如č,ň和ť)。它们在itextsharp生成的pdf中消失。
I am having trouble with some special slovak characters (for example č, ň and ť). They are disappearing in the itextsharp generated pdf.
从我能够找到的,这个问题与我的 BaseFont的编码有关
。目前我使用的是:
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)
有人建议这应该有效:
BaseFont.CreateFont(BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED)
但它抛出此异常错误:
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?
推荐答案
问题在于:
BaseFont.CreateFont(BaseFont.HELVETICA ...
BaseFont.HELVETICA
是标准类型1字体,不能用于您的斯洛伐克字符。您需要使用具有正确字形的字体:
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)));
}
这篇关于iTextSharp和特殊字符(斯洛伐克字素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文