You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PDFBox合并PDF/A后无法通过avepdf校验的问题求助

问题:PDFBox合并PDF/A文件后无法通过指定校验工具的结构类型校验

我用PDFBox合并两个合法的PDF/A文件,当前代码如下:

PDFMergerUtility mergerUtility = new PDFMergerUtility();

File file = new File("example/c.pdf");

mergerUtility.addSource(new File("example/a.pdf"));
mergerUtility.addSource(new File("example/b.pdf"));

mergerUtility.setDestinationFileName(file.getAbsolutePath());

try {
    mergerUtility.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
} catch (IOException ex) {
    throw new RuntimeException("Unable to merge", ex);
}

File inputFile = new File("example/c.pdf");
PDDocument doc = PDDocument.load(inputFile);

File orig = new File("example/a.pdf");
PDDocument origDoc = PDDocument.load(orig);
File orig2 = new File("example/b.pdf");
PDDocument orig2Doc = PDDocument.load(orig2);
PDStructureTreeRoot treeRoot = origDoc.getDocumentCatalog().getStructureTreeRoot();
PDStructureTreeRoot treeRoot2 = orig2Doc.getDocumentCatalog().getStructureTreeRoot();
treeRoot.setKids(treeRoot2.getKids());
doc.getDocumentCatalog().setStructureTreeRoot(treeRoot);

List<PDOutputIntent> outputIntents=new ArrayList<>();
outputIntents.add(doc.getDocumentCatalog().getOutputIntents().get(0));
doc.getDocumentCatalog().setOutputIntents(outputIntents);
doc.save("example/d.pdf");
doc.close();

通过将OutputIntent与第一个文件保持一致,已经解决了大部分问题,但在指定的PDF/A校验工具中仍存在2个“非标准结构类型未映射到任何功能等效的标准类型”错误,排查后确认是合并产物中的THead和TBody导致的。

我尝试复用其中一个原文件的PDStructureTreeRoot并合并另一个的子节点,错误数量减半,但仍无法生成合法的PDF/A文件。该合并产物能通过多数PDF/A校验工具,但公司要求必须通过该指定工具校验,且两个输入文件本身都是合法的PDF/A,现寻求可行的解决思路。

补充:我已经尝试合并两个PDStructureTreeRoot(代码中已包含相关逻辑),但问题仍未解决。

内容的提问来源于stack exchange,提问作者LiefLayer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 19:41:16