我正在尝试使用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();