Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run javascript automatically on every PDF file opening

New Here ,
Oct 15, 2024 Oct 15, 2024

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!

TOPICS
Acrobat SDK and JavaScript
551
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2024 Oct 15, 2024

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2024 Oct 15, 2024

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. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 16, 2024 Oct 16, 2024

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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 16, 2024 Oct 16, 2024
LATEST

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

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 16, 2024 Oct 16, 2024

Great explanation and justifies the behaviour I'm having!

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