Hi Michael,
I'm afraid support for optional content groups has not reached the stage
that they are checked when painting pages. You'll have to dive in and
add filtering for disabled OCGs.

As a starting point, see org.apache.pdfbox.pdfviewer.PageDrawer's
constructor which points you to the properties file that defines the
Operator implementations for PageDrawer. There, implementations for
BMC/BDC/EMC are missing. These will have to be implemented in a way that
painting operators are suppressed for a disabled OCG.

Jeremias Maerki


On 20.09.2012 14:43:41 Michael Karnerfors wrote:
>  
> 
> 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