Copy link to clipboard
Copied
I have 100+ (geo-referenced) pdfs, in which I need to rename some of the layers. E.g. "If the pdf contains a layer named abc, it should be renamed to def, if it contains a layer a23, it should be renamed to c47, etc.". So I have a list of the names I want to replace, and I need to do that across all pdfs (some of the layers are inside groups or nested groups). And I'm looking for a way to automate/script this.
I'm not very familiar with the Adobe products, so I'm not even sure where to start. I can see that Acrobat can do the renaming, and also preserves the geo-referencing info in the pdf when saved, but it doesn't seem very scriptable from what I can find (it seems to mostly be about adding javascript to the pdf, not executing it across multiple pdfs). Illustrator seems more scriptable, but if I open a pdf in Illustrator, it doesn't show the layer names that I'm looking for, so it seems to have a different view of what a layer is.
I'm happy to code in javascript, bat or whatever is relevant. Any input is appreciated.
Copy link to clipboard
Copied
Acrobat can rename layers, if that's what you're dealing with.
Have a look at the name property of the OCG object in the Acrobat JS API Reference.
And if you have Acrobat Pro then you can run that code as a part of an Action on multiple files.
Copy link to clipboard
Copied
You can access the layers (Optional Content Groups, or OCGs) through Acrobat JavaScript. Here's a trivial example of a search-and -rename function:
var layers = this.getOCGs(pageNum);
for (var i=0;i<layers.length;i++) {
if (layers.name == "change-me") layers.name = "new-name";
}
Note that OCGs exist on a per-page basis, so for multi-page documents you will need to handle that in your code (by looping through pageNum, starting at zero, until you find the page with your layer on it).
You can run scripts through the JS console while testing them (Ctrl-J / CMD-J) then put them inside an Action for batch editing once they're doing what you want.
Full documentation on the JavaScript API is in the Acrobat SDK.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now