如何使用Pdfbox禁用(隐藏)可选内容组(OCG)

时间:2019-07-09 17:36:20

标签: java pdfbox

我正在尝试使用pdfbox禁用OCG。我尝试了下面的代码,但它没有禁用OCG。任何帮助都将不胜感激。

public void OCGDelete(PDDocument doc, String OCName) throws IOException {

        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        PDOptionalContentProperties props= catalog.getOCProperties();
        ByteArrayOutputStream pdfOutStream = new ByteArrayOutputStream();


        List<String> ocgNames = Lists.newArrayList(props.getGroupNames());
        if(ocgNames.contains(OCGName)) {
            PDOptionalContentGroup group = props.getGroup(OCGName);
            props.setGroupEnabled(group, **false**);
        }

        doc.getDocumentCatalog().setOCProperties(props);

        doc.save(pdfOutStream);

        FileOutputStream out = new FileOutputStream(
                new File("test/emitted/OCGResult.pdf"));
        out.write(pdfOutStream.toByteArray());
        out.close();

0 个答案:

没有答案