Highlighted

How to include Document level JavaScript in Adobe Acrobat Standard DC for all documents.

Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

I have folder level Javascript at 'C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts'. The script at this location executes when Adobe App is opened, and in this script we already have code to add custom menu items. At this point "app.activeDocs" is null or empty.

I would like to execute a javascript at Document level so that I can get current 'Doc' object and set Actions (DidSave,WillClose) using 'myDoc.setAction("DidSave", "TrustedCustomSave();");'

Also, this Document level javascript needs to be applicable for all pdf documents.

version- AdobeAcrobat Standard DC

Please suggest a way to set actions (DidSave,WillClose) on Document load.

Any help would be much appreciated.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Yes.

TOPICS
Acrobat SDK and JavaScript

Views

102

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

How to include Document level JavaScript in Adobe Acrobat Standard DC for all documents.

Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

I have folder level Javascript at 'C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts'. The script at this location executes when Adobe App is opened, and in this script we already have code to add custom menu items. At this point "app.activeDocs" is null or empty.

I would like to execute a javascript at Document level so that I can get current 'Doc' object and set Actions (DidSave,WillClose) using 'myDoc.setAction("DidSave", "TrustedCustomSave();");'

Also, this Document level javascript needs to be applicable for all pdf documents.

version- AdobeAcrobat Standard DC

Please suggest a way to set actions (DidSave,WillClose) on Document load.

Any help would be much appreciated.

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Yes.

TOPICS
Acrobat SDK and JavaScript

Views

103

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 20, 2020 0
Most Valuable Participant ,
Aug 20, 2020

Copy link to clipboard

Copied

Folder level JavaScript runs and completes before any document is opened. Acrobat has no mechanism for the folder level script to sit and wait for docs to open. You have to take some action (interactive or external) to run the script at document level. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 0
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

Thanks for the information and prompt response. 'setInterval' idea seems to be working out, but not 100% there yet.

Appreciate your help.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

You'll seed to set an interval that will look for changes to the items in app.activeDocs and keep track of which files you've updated... maybe by setting a metadata property. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 1
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

It seems to be working. I will provide a detail update tomorrow. Thank you very much for the 'interval' idea and prompt response.

But, When setAction(willClose,didSave) is added via Javascript, even though there were no changes to the document by the user, when I try to close- it gives Adobe save warning "Do you want to save changes to [filename] before closing?". Technically, it makes sense as javascript updated 'doc' object. However, from the perspective of the user no changes were made to the document, so they should not see the warning message, right. 

So, do you have any suggestions how to work around this issue/behaviour?

Appreciate your help.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 0
Community Beginner ,
Aug 20, 2020

Copy link to clipboard

Copied

I think checking for document dirty will do the trick?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 0
Adobe Community Professional ,
Aug 20, 2020

Copy link to clipboard

Copied

Yes.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 20, 2020 1
Most Valuable Participant ,
Aug 21, 2020

Copy link to clipboard

Copied

If you don't save the file after setting the action it won't work, of course...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
Adobe Community Professional ,
Aug 21, 2020

Copy link to clipboard

Copied

Add

doc.save(doc.path)

to your script after injecting the actions

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
Community Beginner ,
Aug 24, 2020

Copy link to clipboard

Copied

Is there a way to remove injected actions? for example, removing willClose action.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 24, 2020 0
Adobe Community Professional ,
Aug 24, 2020

Copy link to clipboard

Copied

Use a empty script at setAction.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 24, 2020 1
Community Beginner ,
Aug 26, 2020

Copy link to clipboard

Copied

I am trying save document using javascript - doc.save(doc.path). But it throws an error - TypeError:doc.save is not a function.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 0
Adobe Community Professional ,
Aug 26, 2020

Copy link to clipboard

Copied

Use this.saveAs

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 26, 2020 1
Community Beginner ,
Aug 29, 2020

Copy link to clipboard

Copied

Can I differentiate between app close and document close? or is there a set action for App close? 

I have a custom function for Will Close and in that custom function I am making couple of Net.Http calls. This works if document is closed, meaning - all calls are made. But if I close application will close custom function is executed but not all methods in will close function, just the first one gets executed and it exits. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 29, 2020 0
try67 LATEST
Most Valuable Participant ,
Aug 29, 2020

Copy link to clipboard

Copied

The app closing does not trigger any event you can use.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 29, 2020 0