我的 PDF 无法使用 Adobe Reader 正确显示。其他 PDF 阅读器没问题,所以这一定是语法问题,因为我听说 Adobe Reader 对 PDF 语法更严格。字体似乎是应有的两倍大,但水平间距是正确的,这使得字体相互重叠。
这是我的 C# 代码(字体创建代码在本文末尾)。
Font officialUseFont = EmbeddedResources.CreateDesignFont(webform);
PdfContentByte officialUseCanvas = _stamper.GetOverContent(3);
ColumnText.ShowTextAligned(officialUseCanvas, Element.ALIGN_CENTER, new Phrase(webform.Text, officialUseFont), posX, posY, 0);
我正在使用 iTextSharp 5.4.2.0 和运行时 v2.0.50727。
我一定嵌入了一些字体,因为西里尔字母和中文字母以前不工作,但现在可以工作。PDF 中存在的表单字段填充了西里尔字符,没有任何问题,它只是导致问题的画布。
public Font CreateDesignFont(IForm webform)
{
var baseFont = GetBaseFont(fontNamespace.Length, selectedFontName);
return new Font(baseFont, webform.FontSize);
}
private static BaseFont GetBaseFont(int fontNamespaceLength, string selectedFontName)
{
byte[] fontBuffer;
using (var stream = (Assembly.GetExecutingAssembly().GetManifestResourceStream(selectedFontName)))
{
fontBuffer = new byte[stream.Length];
stream.Read(fontBuffer, 0, fontBuffer.Length);
}
var fontfile = selectedFontName.Substring(fontNamespaceLength);
var customFont = BaseFont.CreateFont(fontfile, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, BaseFont.CACHED, fontBuffer, null);
return customFont;
}