As far as I know, you can't add or merge a layer directly, but you can add an OCG using the addWatermarkFromFile() method.
Regarding the console, simply execute your code and then either select the name of the variable you want to examine, or type it, and press Ctrl+Enter. It will display its value. For example, if you execute this code:
var a = 2 + 5;
The result will be "7".
Thanks for the reply try67!
It's good to know there isn't a lot that can be done with js... Not knowing the range of possibilities is likely my biggest problem. Do you know if the Acrobat SDK would give deeper hooks into a document? I would be in heaven if I could just write something in Python and not have to run Acrobat or use any of it's built in features. I'll give the addWate3rMarkFromFile() method a try... I haven't in the past because I assumed, since it's a watermark, visibility could not be toggled like the other layers.
Since my last message I played a bit more with the console and found my troubles were caused by not hitting ctrl+enter after each line. Instead I would write a few lines then ctrl+enter to test and it would fail.
1 person found this helpful
Don't get me wrong, you can achieve a lot with JS, but there's also a lot that can't be achieved, if that makes sense...
After you create the watermark you can change its settings like any other OCG.
To run multiple lines in the console you must select them all and then press Ctrl+Enter.
Anyway, for questions about the Acrobat SDK you should try that forum.
1 person found this helpful
Some things can be done via the SDK, by manipulating the PDOCG object, but it's all low-level stuff - you have to work with the object memberships themelves, we don't have nice wrapper functions like "move_to_layer_x" or "replace_layer_x", and membership of a PDOCG dictionary isn't directly related to an object's presence in the document (deleting the PDOCG doesn't delete the object). There's an example of using OCGs in Snippet Runner (a C++ plugin in the SDK) but nothing that directly replicates the "add to existing layer" command in the UI. It is possible to do that, but you'll have to write the code from scratch.
Can't edit, remove, replace, an OCG with js.... Too bad. I would really like to be able to deeply edit PDFs and after looking at the SDK it's way more effort than I want to put into this right now.
Regardless, I used addWatermarkFromFile() and though the result is not exaclty what I want it's adequate. Using js first in Illustrator to rebuild the data table I needed then again to insert the corrected data into the original PDF I was able to repair thousands of PDFs that would have taken perhaps three weeks to first re-generate then QC.
Thank you both for all your help!