PDFBox 2.0.27导入OCG PDF时禁用图层复现问题求助
PDFBox 2.0.27及更早版本OCG显示问题与移除方案咨询
在PDFBox 2.0.27及更早版本中,将页面导入为PDFormXObject并通过PDPageContentStream绘制时,所有已禁用的可选内容组(OCG)会重新显示,这完全阻碍了分层PDF的相关工作。现询问是否有彻底移除OCG的方法,同时排查以下测试代码是否存在错误。
测试代码片段1
PDDocument tmpPDFDocument = PDDocument.load(server.pdf()); LayerUtility utility = new LayerUtility(tmpPDFDocument); PDFormXObject mapPDF = utility.importPageAsForm(tmpPDFDocument, 0); stream.drawForm(form);
测试代码片段2
public void createFile2(File output, LayoutPage layoutPage, LocalServer server) throws IOException { if (!output.exists() && !output.createNewFile()) throw new IOException(); PDRectangle box = new PDRectangle(0f, 0f, 3000, 3000); PDPage page = new PDPage(box); PDDocument document = new PDDocument(); document.addPage(page); PDPageContentStream stream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.OVERWRITE, true, true); PDDocument tmpPDFDocument = PDDocument.load(server.pdf()); LayerUtility utility = new LayerUtility(tmpPDFDocument); utility.wrapInSaveRestore(tmpPDFDocument.getPage(0)); PDFormXObject mapPDF = utility.importPageAsForm(tmpPDFDocument, 0); stream.drawForm(mapPDF); stream.close(); document.save(output); document.close(); }
内容的提问来源于stack exchange,提问作者Guyard
相关产品推荐
相关产品推荐

