关于 PDF/A 代字体编码的问题
Problem about font encoding in PDF/A generation
所以这是我的问题:
我目前正在开发一个 java 应用程序,它将文档归档在 PDF/A-1 中。我正在使用 PdfBox 生成 pdf,但由于字体原因我无法生成有效的 PDF/A-1 pdf。字体嵌入在 pdf 文件中,但是这个网站:https://www.pdf-online.com/osa/validate.aspx 告诉我这不是有效的 PDF/A 因为:
The key Encoding has a value Identity-H which is prohibited.
我在互联网上查看这个 Identity-H 编码是什么,它似乎是字体的编码方式,例如 ansi 编码。
我已经尝试过使用不同的字体,如 Helvetica 或 arial unicode Ms,但没有任何效果,总是有这个 Identity-H encoding.I我有点迷失了编码中的所有这些混乱,所以如果有人可以向我解释这会很棒。这也是我编写的用于在 pdf 中嵌入字体的代码:
// load the font as this needs to be embedded
PDFont font = PDType0Font.load(doc, getClass().getClassLoader().getResourceAsStream(fontfile), true);
if (!font.isEmbedded())
{
throw new IllegalStateException("PDF/A compliance requires that all fonts used for"
+ " text rendering in rendering modes other than rendering mode 3 are embedded.");
}
感谢您的帮助:)
问题已解决:
我使用了 apache 的例子:CreatePDFA(我不知道为什么它起作用,而不是我的代码):Example in examples/src/main/java/org/apache/pdfbox/examples
我添加以满足 PDF/A-3 要求:
doc.getDocumentCatalog().setLanguage("en-US");
PDMarkInfo mark = new PDMarkInfo(); // new PDMarkInfo(page.getCOSObject());
PDStructureTreeRoot treeRoot = new PDStructureTreeRoot();
doc.getDocumentCatalog().setMarkInfo(mark);
doc.getDocumentCatalog().setStructureTreeRoot(treeRoot);
doc.getDocumentCatalog().getMarkInfo().setMarked(true);
PDDocumentInformation info = doc.getDocumentInformation();
info.setCreationDate(date);
info.setModificationDate(date);
info.setAuthor("KairosPDF");
info.setProducer("KairosPDF");
info.setCreator("KairosPDF");
info.setTitle("Generated PDf");
info.setSubject("PDF/A3-A");
这是我将文件嵌入 pdf 的代码:
private final PDDocument doc = new PDDocument();
private final PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();
private final PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
private final Map<String, PDComplexFileSpecification> efMap = new HashMap<>();
public void addFile(PDDocument doc, File child) throws IOException {
File file = new File(child.getPath());
Calendar date = Calendar.getInstance();
//first create the file specification, which holds the embedded file
PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFileUnicode(child.getName());
fs.setFile(child.getName());
InputStream is = new FileInputStream(file);
PDEmbeddedFile ef = new PDEmbeddedFile(doc, is);
//Setting
ef.setSubtype("application/octet-stream");
ef.setSize((int) file.length() + 1);
ef.setCreationDate(date);
ef.setModDate(date);
COSDictionary dictionary = fs.getCOSObject();
dictionary.setItem(COSName.getPDFName("AFRelationship"), COSName.getPDFName("Data"));
fs.setEmbeddedFile(ef);
efMap.put(child.getName(), fs);
efTree.setNames(efMap);
names.setEmbeddedFiles(efTree);
doc.getDocumentCatalog().setNames(names);
is.close();
}
剩下的唯一问题是验证中的错误:
File specification 'Test.txt' not associated with an object.
希望对大家有所帮助。
所以这是我的问题: 我目前正在开发一个 java 应用程序,它将文档归档在 PDF/A-1 中。我正在使用 PdfBox 生成 pdf,但由于字体原因我无法生成有效的 PDF/A-1 pdf。字体嵌入在 pdf 文件中,但是这个网站:https://www.pdf-online.com/osa/validate.aspx 告诉我这不是有效的 PDF/A 因为:
The key Encoding has a value Identity-H which is prohibited.
我在互联网上查看这个 Identity-H 编码是什么,它似乎是字体的编码方式,例如 ansi 编码。
我已经尝试过使用不同的字体,如 Helvetica 或 arial unicode Ms,但没有任何效果,总是有这个 Identity-H encoding.I我有点迷失了编码中的所有这些混乱,所以如果有人可以向我解释这会很棒。这也是我编写的用于在 pdf 中嵌入字体的代码:
// load the font as this needs to be embedded
PDFont font = PDType0Font.load(doc, getClass().getClassLoader().getResourceAsStream(fontfile), true);
if (!font.isEmbedded())
{
throw new IllegalStateException("PDF/A compliance requires that all fonts used for"
+ " text rendering in rendering modes other than rendering mode 3 are embedded.");
}
感谢您的帮助:)
问题已解决:
我使用了 apache 的例子:CreatePDFA(我不知道为什么它起作用,而不是我的代码):Example in examples/src/main/java/org/apache/pdfbox/examples
我添加以满足 PDF/A-3 要求:
doc.getDocumentCatalog().setLanguage("en-US");
PDMarkInfo mark = new PDMarkInfo(); // new PDMarkInfo(page.getCOSObject());
PDStructureTreeRoot treeRoot = new PDStructureTreeRoot();
doc.getDocumentCatalog().setMarkInfo(mark);
doc.getDocumentCatalog().setStructureTreeRoot(treeRoot);
doc.getDocumentCatalog().getMarkInfo().setMarked(true);
PDDocumentInformation info = doc.getDocumentInformation();
info.setCreationDate(date);
info.setModificationDate(date);
info.setAuthor("KairosPDF");
info.setProducer("KairosPDF");
info.setCreator("KairosPDF");
info.setTitle("Generated PDf");
info.setSubject("PDF/A3-A");
这是我将文件嵌入 pdf 的代码:
private final PDDocument doc = new PDDocument();
private final PDEmbeddedFilesNameTreeNode efTree = new PDEmbeddedFilesNameTreeNode();
private final PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
private final Map<String, PDComplexFileSpecification> efMap = new HashMap<>();
public void addFile(PDDocument doc, File child) throws IOException {
File file = new File(child.getPath());
Calendar date = Calendar.getInstance();
//first create the file specification, which holds the embedded file
PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFileUnicode(child.getName());
fs.setFile(child.getName());
InputStream is = new FileInputStream(file);
PDEmbeddedFile ef = new PDEmbeddedFile(doc, is);
//Setting
ef.setSubtype("application/octet-stream");
ef.setSize((int) file.length() + 1);
ef.setCreationDate(date);
ef.setModDate(date);
COSDictionary dictionary = fs.getCOSObject();
dictionary.setItem(COSName.getPDFName("AFRelationship"), COSName.getPDFName("Data"));
fs.setEmbeddedFile(ef);
efMap.put(child.getName(), fs);
efTree.setNames(efMap);
names.setEmbeddedFiles(efTree);
doc.getDocumentCatalog().setNames(names);
is.close();
}
剩下的唯一问题是验证中的错误:
File specification 'Test.txt' not associated with an object.
希望对大家有所帮助。