Skip to main content
Participant
Oct 15, 2024 4:27 PM UTC
Question

Run javascript automatically on every PDF file opening

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:

  1. 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.

  2. 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!

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

try67
Community Expert
Community Expert
Oct 15, 2024 5:44 PM UTC

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.

Translate
Thom Parker
Community Expert
Community Expert
Oct 15, 2024 8:31 PM UTC

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. 

 

 

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participant
Oct 16, 2024 8:33 AM UTC

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!

Translate