【发布时间】:2012-10-26 11:37:24
【问题描述】:
我正在尝试使用 itext 从 pdf 文件创建 pdf/a 文件。一切顺利,我得到一个 pdf/a 文件。但是当我在这里查看http://www.pdf-tools.com/pdf/validate-pdfa-online.aspx 时,我会收到类似的错误
The width for character 1 in font 'ArialRegular' does not match.
The width for character 2 in font 'ArialRegular' does not match.
The width for character 3 in font 'ArialRegular' does not match.
我该如何解决这个错误?
PdfReader pdfReader = new PdfReader(file);
FontFactory.defaultEmbedding = true;
BaseFont bf = BaseFont.createFont(FONT, BaseFont.CP1252, BaseFont.EMBEDDED);
while (currentpagenumber < pdfReader.getNumberOfPages()) {
document.newPage();
currentpagenumber++;
finalpagenumber++;
page = pdfAWriter.getImportedPage(pdfReader, currentpagenumber);
cb.addTemplate(page, 0, 0);
cb.beginText();
cb.setFontAndSize(bf, 18);
cb.showTextAligned(PdfContentByte.ALIGN_CENTER, finalpagenumber+"", 520, 5, 0);
cb.endText();
ICC_Profile icc = ICC_Profile.getInstance(new FileInputStream(PROFILE));
这是基本代码。我还尝试使用 pdfdictionary 查找每个页面中使用的字体.. 并尝试将其嵌入为基本字体.. 但无法工作..
【问题讨论】:
-
那么,您如何尝试使用 iText 从(通用)PDF 创建 PDF/A?我问是因为这样的转换根本不是 iText 的功能。另请参阅 iText 邮件列表上的 here。
-
我尝试使用 pdfcontentbyte 复制 pdf 文件并使用 pdfAwriter 将其写入 pdf/a 文件(正是我们如何使用 pdfAWriter 添加段落)
-
我知道这可能不是正确的做法。但我只收到一个我提到的错误。我不确定如何嵌入所需的字体
-
Hhmmm,直接使用内容字节可能真的很复杂,因为您必须考虑为原始页面定义的所有资源等。您是否有一些生成 PDF 的小样本来显示该问题?您可以在iText in Action examples 中找到许多使用 iText 的示例,其中许多以一种或另一种方式使用字体。
-
在您现在添加了代码示例之后:恐怕代码无法满足您的目的。 PdfAWriter.getImportedPage 和 ContentByte.addTemplate 都没有做任何事情来确保 PDF/A-ishness。如果在原始 PDF 中定义页面的对象尚未满足 PDF/A 要求,则结果文档中的页面也不会满足,并且还会复制原始文档中的任何错误。结果 PDF 只会声称符合 PDF/A(相应地设置了一些元数据。此外,使用 getImportedPage 将删除所有交互功能,包括数字签名等内容。