【发布时间】:2019-03-15 09:43:13
【问题描述】:
我正在将我的 PDFBox 1.8.x 迁移到 2.0.12,并且必须进行一些更改。
我无法弄清楚的最后一个发生在下面的代码中。
public static byte[] mergeDocuments(byte[] document1, byte[] document2) {
try (PDDocument pdDocument1 = load(document1); PDDocument pdDocument2 = load(document2)) {
final List<PDPage> pages1 = getPages(pdDocument1);
final List<PDPage> pages2 = getPages(pdDocument2);
pages1.addAll(pages2);
return createDocument(pages1);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private static List getPages(PDDocument pdDocumentTarget) {
return pdDocumentTarget.getDocumentCatalog().getAllPages();
}
最后一行发生错误,我必须将旧的“.getAllPages()”更改为“.getPages”,但随后我将 PDPageTree 作为返回而不是 List。
代码是几年前写的,不是我写的。我已经尝试过一些事情,比如强制转换或更改类型,但它总是会在不同的地方导致错误。
提前感谢您的帮助
【问题讨论】:
-
除了答案,你也可以试试
document.getPage(i)和document.getNumberOfPages()