pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Karnerfors" <michael.karnerf...@digitalcontext.se>
Subject Getting PDFImageWriter to honor disabled Optional Content Groups
Date Thu, 20 Sep 2012 12:43:41 GMT
 

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(); }

}


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message