1

I know about Doc.SetOCGOrder() and the likes, but apparently the Acrobat API does not provide means to remove layers (aka optional content groups, ocgs), only to hide them from users while leaving them accessible via scripting.

I'm not forced to use Acrobat, in fact I'd prefer a FOSS-solution (or at least freeware) using e.g. or . edit There is another post using , which is unfortunately not free. Is there any way to port that behaviour to Acrobat's JS or ? Essentially the answer seems to loop through every page's content, which seems to include the layers.

(Concerning merging, I notice pdftk does remove layers when merging multiple files, so one can simple pdftk A=input.pdf B=input.pdf cat A1-end output output.pdf.)

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
  • WIP-idea: Make layers invisible first, then use `pdftk` to merge. But does that truly delete the layer content? – Tobias Kienzler Feb 23 '17 at 11:07
  • Do you want to remove the content of the layer together with its definition or do you merely want to remove the information that that content is in a layer? Furthermore, solutions for which programming environments are you interested in? – mkl Feb 23 '17 at 11:30
  • @mkl I want to truly remove the layer's content. Otherwise I could use Acrobat's API and change the properties (though I'm not sure whether I'd have to simply use `locked` and `initState` or modify/empty the `intents` - in fact, https://www.uvsar.com/projects/acrobat/indesignfixups/ suggests I'd have to "remove" it via `setOCGOrder`). – Tobias Kienzler Feb 23 '17 at 11:51
  • 1
    In that case you might want to use the iText (a Java PDF library) utility class `OCGRemover`, cf. [this answer](http://stackoverflow.com/a/17718641/1729265). – mkl Feb 23 '17 at 14:03
  • @mkl Thanks, I'll have a look at it as well – Tobias Kienzler Feb 23 '17 at 14:05

2 Answers2

0

My approach so far: For the relevant layers obtained via GetOCGs() set locked=true and both initState=false and state=false. Then use SetOCGOrder() to remove the layer from the layers view. Unfortunately this is not perfect, since at least in Acrobat DC I can still select "show all layers" in the layers panel, which still shows the layer. One could merge all layers now, but neither did I find an option to achieve that programmatically nor do I believe that would actually remove the hidden layer's elements.

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
0

You can't do it programmatically but you can create an Action that will process a folder full of PDF files using Adobe Acrobat. Set the Action to use the PDF Optimizer to discard hidden layers and flatten visible ones. See the graphic.

enter image description here

joelgeraci
  • 4,606
  • 1
  • 12
  • 19