I'm using PDFBox 3.0.0 to combine some PDF files.  One of the files uses an Optional Content Group. Note that this code has been working just fine for many other files both with and without OCG's.

For this file, I get this exception:

java.lang.IllegalArgumentException: Provided dictionary is not of type 'COSName{OCG}'

    at org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentGroup.<init>(PDOptionalContentGroup.java:48) ~[pdfbox-3.0.0.jar:3.0.0]

Code:

*if*(obj*instanceof*COSDictionary) {

COSDictionary dict= (COSDictionary) obj;

COSName dType= dict.getCOSName(COSName.*/TYPE/*);

*if*(dType== *null*) {

*continue*;

}

*if*(dType.equals(COSName.*/OCG/*)) {

*/log/*.debug("addOCGs: OCG {}", dict);

PDOptionalContentGroup grp= *new*PDOptionalContentGroup(dict);

ocProps.addGroup(grp);

ocProps.setGroupEnabled(grp, layersON.contains(grp.getName()));

changed= *true*;

}

}

 It's failing on the "new PDOptionalContentGroup(dict)" call.
Any ideas on why?

Reply via email to