Hello all,

 

I want to use PDFBox to load a PDF file, disable an Optional Content Group,
and then use PDFImageWriter  to output the resulting document to an image
file. 

 

The problem is that the image writer does not seem to honor the fact I
disabled the OCG and still outputs the layer. 

 

When I write the document as a new PDF file, Adobe Acrobat honors the fact I
turned the OCG off. 

 

Does anyone know how you can make PDFImageWriter honor the disabled OCG?

 

With best regards

/Michael

 

Code Sample: 

 

String password = "";

String pdfFile = "input_file.pdf";

String outputPrefix = "output_file";

String imageFormat = "png";

int startPage = 1;

int endPage = Integer.MAX_VALUE;

String color = "rgba";

int resolution = 300;

 

PDDocument document = null;

 

try {

document = PDDocument.load(pdfFile);

 

PDDocumentCatalog catalog = document.getDocumentCatalog();

PDOptionalContentProperties ocgs = catalog.getOCProperties();

                

           for(String groupName : ocgs.getGroupNames()) {

           if(groupName.startsWith("SmartMarks")) {

                                 ocgs.setGroupEnabled(groupName, false);

}

}

 

           PDFImageWriter imageWriter = new PDFImageWriter();

imageWriter.writeImage(document, imageFormat, password, startPage, endPage,
outputPrefix, imageType, resolution);

 

} catch (Exception e) {

System.err.println(e);

} finally {

if (document != null) { document.close(); }

}

Reply via email to