Run javascript automatically on every PDF file opening
Copy link to clipboard
Copied
I have a script made in javascript that works well if I execute manually from each document.
But my need is to have this executing on each PDF file open automatically:
if (this.xfa !== undefined) {
app.alert({
cMsg: "Warning: This document contains a XFA form!",
nIcon: 2,
Title: "XFA Document Detected" });
} else {
app.alert({
cMsg: "This is a normal PDF.",
nIcon: 3,
Title: "Normal PDF"
});
}
When I have this script on javascript folder (C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts), it doesn't work as expected and there are two behaviours happening:
- It always goes no "else" condition, even if the file contain XFA form, I guess that happens because "this.xfa" condition is not met. I tried to find in Adobe Acrobat SDK the reference alternatives but I couldn't find a way of solving/finding the reference.
- If I already have a file opened and try to open a second file, nothing happens. I guess because the script is only valid triggered at Adobe Acrobat startup and I should have a way of listening an event for "file open" action but also I couldn't find any information regarding this.
I'm trying to arrange a solution for a customer that has an issue regarding PDF's that contain LiveCycle XFA forms and while Adobe doesn't provide an option to deal with PDF with XFA forms. I already suggest in Adobe's UserVoice platform.
I would like to hear from some expert if there is anyway of achieving this or if I'm in a dead spot.
Thank you!
Copy link to clipboard
Copied
No, there isn't. The folder-level scripts are executed before any file is opened, so the "this" object does not point to a document at that time. And Acrobat doesn't have a "listener" object, so this won't work, I'm afraid.
Copy link to clipboard
Copied
There is a workaround, which is to write a plug-in that runs the script when a document opens. But of course if you're going to write a plug-in, it could just do whatever the script was going to do.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Hi Thom,
Thank you for giving me an alternate path, that seems to be the only way to go.
I will try to understand how can I create a plugin and if it's fisable.
Thank you for both for your help and guidance!
Copy link to clipboard
Copied
Plug-ins require specialized developement software significantly more programming skills than scripting. Here's a link the plug-in developers guide.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/plugin/index.html
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Great explanation and justifies the behaviour I'm having!

