我有适用于 iText 7.1.5 的代码,可在现有 PDF/A 文档中填充 AcroForm。为此,我还创建了一个 PdfFont。 现在,我正在尝试从 iText 7.1.5 升级到 7.2.5,但似乎 7.1.7 发生了变化,这破坏了我当前的实现并导致上述错误。
当前代码看起来像这样(简化):
using (var pdfDocument = new PdfADocument(pdfReader, writer))
{
PdfFont fontCourier = PdfFontFactory.CreateFont(fontBytes,
PdfFontFactory.EmbeddingStrategy.FORCE_EMBEDDED); // 2nd parameter used to be 'true' in 7.1.x
var acroForm = PdfAcroForm.GetAcroForm(pdfDocument, false);
var field = acroForm.GetField(formField.Name);
field.SetValue(fieldValue, fontCourier, fontSize);
}
在处理 pdfDocument 时,我发现我的字体没有嵌入,它曾经与 7.1.5 一起使用,并通过了我使用其他工具对生成的文档执行的所有验证。
Courier 是标准字体之一,参见 PDF 规范 ISO 32000-2 第 9.6.2.2 段。 这意味着字体被“嵌入”到 pdf 处理器中,如 Adobe Acrobat。 如果要使用 Courier,请通过以下方式创建字体:
PdfFont fontCourier = PdfFontFactory.createFont(StandardFonts.COURIER);