Document Level Scripts With Acrobat Standard

If you are using Adobe Acrobat Standard, you’ve probably noticed that you cannot add document level scripts to PDF documents. This is a limitation of the user interface, Acrobat Standard can actually add such scripts (and document actions), but it requires some JavaScript programming.

I’ve done that job for you. Download the script addDocumentScripts.js and save it on your local computer.

To install the script, use the information from my post “Acrobat JavaScripts – Where do they go”

Once the file is saved in either the application or the user level JavaScripts directory, you can open a PDF file and select the new menu item “File>Add JS Scripts”.

This will bring up the following dialog:

Add Document Scripts Dialog

First select what type of script you want to add (the default is “Document Level”):

  • Document Level Script
  • Document Action:
    • Will Close
    • Will Save
    • Did Save
    • Will Print
    • Did Print

The script name is only necessary for a document level script, the document actions do not require a name (there can only be one per type).

When you fill in the script, make sure you paste from your text editor: Edit the script in an editor and then just paste the final script, do not edit the script in this dialog. The reason for this is that you will not be able to retrieve the script with Acrobat Standard, only Acrobat Pro allows you to do that. This means that any changes you make to your script in the input field on this dialog will be lost – they will be saved in the document, but you will not be able to retrieve or to edit them.

This is not the most elegant way to add scripts to a document, but if all you have is Acrobat Standard, at least you can.

This entry was posted in Acrobat, JavaScript, PDF and tagged , , . Bookmark the permalink.

22 Responses to Document Level Scripts With Acrobat Standard

  1. Nkosinathi Makhaye says:

    Hi my name is Nkosinathi Makhaye my comment is if the adobe can be made easy to download I think that would be a good idea a specially for those who find so difficult to following the instrutions like me of wich its not only me is many of us out there thank you.

  2. Karl Heinz Kremer says:

    Nkosinathi, unfortunately I don’t understand your question. What would you like to be easier to download?

  3. JT says:

    This is fantastic, thank you for sharing. Just a quick question on how this works with the system, how do you make changes/corrections to a document level script that is added this way? Can you just add a corrected version provided you use the same script name or do you need to start over with the file prior to adding the document level script.

  4. Karl Heinz Kremer says:

    You can just replace a script with a new script with the same name.

  5. Balgad says:

    Amazing! I’ve searched so much for a solution and now this works! Btw, sometimes does not update the document-level script in spite of I replace the script with the same name. But after some tries (save, reopen in reader, etc) it works again.

    So this is really cool!

    Thanks

  6. Pep says:

    Hi Karl,
    I followed all your steps, but I’m not able to save the script for document-level. Could you please provide an example?

  7. Karl Heinz Kremer says:

    Pep, you can for example put the following one line script into a document level script to see the effect:

    app.alert("Document Level Script");

    This will display a message box when the PDF gets loaded in Adobe Acrobat or Reader.

  8. GP says:

    I have tried pasting a simple app.alert but it is not working. The script name is zzformdocopen.

  9. Karl Heinz Kremer says:

    GP, as I’ve reported in an email to you, the problem is a bug in my code, and I’ve updated the linked script. Thanks for bringing this to my attention.

  10. GP says:

    Is there a character limit to a document level script?

  11. Karl Heinz Kremer says:

    GP, I am not aware of one.

  12. Marc says:

    Is there a way to write a script for an Acrobat Action that will place a Document Level Script in Acrobat DC? I’ve been searching the SDK and Google but no luck yet.

    I was thinking there should be some way to use the setAction(); method but not sure if that’s an option…

    What I’d like is to add default variables for some text fields on the document level to be used by several fields.

  13. Marc says:

    Thanks Karl. That works great!

  14. Moni says:

    I have Adobe Acrobat Pro DC installed in PC. I want to add a script wherein I can change all tags to tags. I am able to see h1 tags in my document. But how to get all the tags existing in this document using Javascript code? For running javascript, I am using Action Wizard. Please tell me if I am on the right track.

  15. Karl Heinz Kremer says:

    Moni, JavaScript does not have access to tags in a PDF file. You would have to write an Acrobat plug-in to collect the tags. Creating a plug-in is much more complex than programming in JavaScript (and therefore – if you need to pay somebody to do that – also more expensive). If you are interested in my professional services to create such a plug-in for you, please get in touch with me via email (my email address is on the “About” page).

  16. irene says:

    I missed your point about the app being uneditable once implemented and now I am getting this error:

    NotAllowedError: Security settings prevent access to this property or method.
    App.trustedFunction:11:Page undefined:Open

    Please tell me there’s a way to override this 🙁

  17. Karl Heinz Kremer says:

    Irene, not sure what exactly you are referring to, but the script cannot be edited once you add it to the document using this technique. When you have Adobe Acrobat Pro, you can edit document level scripts. With Standard, you will have to store a copy of your script outside of the PDF file and when you want to edit it, go back to that stored copy, modify it and save it back to the document. That however does not have anything to do with your error. What version of Acrobat are you using?

  18. irene says:

    Standard.

    I saved a duplicate, and tried to implement the code again to the file but it gives me the error, almost as if it is a one-time use.

  19. Joe says:

    How do I get rid of this error:

    NotAllowedError: Security settings prevent access to this property or method.
    Doc.addScript:195:Menu KHK_addJSScripts:Exec

  20. Jason says:

    Hi!
    Thanks for your great work. How to retrieve document level javascripts?

  21. Karl Heinz Kremer says:

    Jason, as I mentioned in the article, this is a one way process with Standard. In order to see what a document level script is, you need Acrobat Pro.

Leave a Reply

Your email address will not be published. Required fields are marked *