I don't think it will be a lot. For someone new to PDFBox's source code the biggest part is probably to understand the execution flow when painting PDF. Basically, one needs to intercept the BMC/MDC/EMC operators and find a clean way to suppress the drawing of content inside the OCGs that are disabled. The decision whether to suppress is easy since the API for that is available. I haven't looked closely at how this would be be done but I can't imagine this will take more than 1-2 days for someone relatively new to PDFBox. No guarantees.
Maybe someone else already has an idea how to do the filtering? Jeremias Maerki On 20.09.2012 16:42:54 Michael Karnerfors wrote: > > Hi Jeremias, > > Ok, understood. Do you have any sense of how much work that might be? > > With best regards, > /Michael > > > > -----Original Message----- > From: Jeremias Maerki [mailto:[email protected]] > Sent: den 20 september 2012 16:15 > To: [email protected] > Subject: Re: Getting PDFImageWriter to honor disabled Optional Content > Groups > > 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(); } > > > > } > >

