Utf 8 iTextSharp和特殊字符(斯洛伐克字母)
我对一些特殊的斯洛伐克字符(例如č、ň和ť)有困难。它们正在itextsharp生成的pdf中消失 据我所知,这个问题与我的Utf 8 iTextSharp和特殊字符(斯洛伐克字母),utf-8,itext,pdf-generation,special-characters,encode,Utf 8,Itext,Pdf Generation,Special Characters,Encode,我对一些特殊的斯洛伐克字符(例如č、ň和ť)有困难。它们正在itextsharp生成的pdf中消失 据我所知,这个问题与我的BaseFont的编码有关。目前我使用的是: BaseFont.CreateFont(BaseFont.HELVETICA, iTextSharp.text.pdf.BaseFont.CP1250, BaseFont.NOT_EMBEDDED) 有人建议这应该有效: BaseFont.CreateFont(BaseFont.HELVETICA, iTextSharp.te
BaseFont
的编码有关。目前我使用的是:
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
有人知道可能的原因和解决方法吗?问题在于:
BaseFont.CreateFont(BaseFont.HELVETICA ...
BaseFont.HELVETICA
是一个字符,不能用于斯洛伐克字符。您需要使用具有正确字形的字体:
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)));
}