这是PDFBox 2.0.2中的一个已知错误。拆分在2.0.1中工作正常,在2.0.3中又可以工作。“错误的”代码已经恢复。问题的原因在这里讨论。长话短说:2.0.2版在每个源页面上进行了深层克隆,从而导致资源重复。
更新:这是一些使用2.0.2的人的解决方法代码:
static public PDPage importPageFixed(PDdocument document, PDPage page) throws IOException{ PDPage importedPage = new PDPage(new COSDictionary(page.getCOSObject()), document.getResourceCache()); InputStream in = null; try { in = page.getContents(); if (in != null) { PDStream dest = new PDStream(document, in, COSName.FLATE_DECODE); importedPage.setContents(dest); } document.addPage(importedPage); } catch (IOException e) { IOUtils.closeQuietly(in); } return importedPage;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)