Highlighted

How to have a Document level Javascript to execuite when combining PDF forms/files

New Here ,
Sep 03, 2020

Copy link to clipboard

Copied

Is there a way to have a javascript run when combining two PDF Forms?

 

I need to hide specific fields in each form that are normally managed by a document level javascript function.  It seems that when merging PDF files, the all javacript scripts embedded in the forms are stripped when merged using the combine files tool.  If merging one file into an open file then only the scripts from file 2 are stripped.

 

FYI, all functions and global variables in each form are unique.

 

I created two forms, each of which has an error readonly form that dislayes if the document is not opened in Acrobat or Reader on either Mac or PC.   Here is a screen shot of the warning message displayed on top of page 1.  It is the first form in the field.  The text and formationg was enteried into the field as ReadWrite then set to ReadOnly when finished.:

 

image.png

 

At the to of the document level javascript of each form is the following (Unique variables and function names in each form).  If all is OK with the viewer and platform the field is hidden:

var _errorForm = 'ErrorField';
var _okViewers = ['Exchange-Pro', 'Exchange', 'Reader']; // From app.viewerType
var _okOSs_SREF = ['MAC', 'WIN'];

function _checkViewer() {
    if ((this._okViewers.indexOf(app.viewerType) >= 0)  && (this._okOSs.indexOf(app.platform) >= 0)){
       // hide Error warning
        this.getField(this._errorForm).hidden = true;
        return true;
    } else {
        this.getField(this._errorForm).hidden = false;
        if (this._okOSs.indexOf(app.platform) < 0) {
            app.alert({
                cMsg: "Only Microsoft Windows and Apple MAC Adobe Readers/Acrobat supported.\n\nThis system Reported OS as " + app.platform,
                nIcon: 3,
                nType: 0,
                cTitle: "OS Not Supported"
            });
        }
        return false;
    }
}

if (this._checkViewer_SREF()) {		// this will run at document startup
    this._openingMessage_SREF();
}

 

The problem is when I combine these two forms from .  An error message to "An incorrect structure found in the PDF file"

image.png

 

This error happens when I addia file from  the "Page Thumbnails" > "Insert File" (Shift+Ctrl+I).

image.png

 

The error does not occur when I use the "Combine Files" tool.

 

Thank you for any guidance you might be able to offer.

 

Alex Lindberg

Topics

Acrobat SDK and JavaScript, PDF forms

Views

33

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 have a Document level Javascript to execuite when combining PDF forms/files

New Here ,
Sep 03, 2020

Copy link to clipboard

Copied

Is there a way to have a javascript run when combining two PDF Forms?

 

I need to hide specific fields in each form that are normally managed by a document level javascript function.  It seems that when merging PDF files, the all javacript scripts embedded in the forms are stripped when merged using the combine files tool.  If merging one file into an open file then only the scripts from file 2 are stripped.

 

FYI, all functions and global variables in each form are unique.

 

I created two forms, each of which has an error readonly form that dislayes if the document is not opened in Acrobat or Reader on either Mac or PC.   Here is a screen shot of the warning message displayed on top of page 1.  It is the first form in the field.  The text and formationg was enteried into the field as ReadWrite then set to ReadOnly when finished.:

 

image.png

 

At the to of the document level javascript of each form is the following (Unique variables and function names in each form).  If all is OK with the viewer and platform the field is hidden:

var _errorForm = 'ErrorField';
var _okViewers = ['Exchange-Pro', 'Exchange', 'Reader']; // From app.viewerType
var _okOSs_SREF = ['MAC', 'WIN'];

function _checkViewer() {
    if ((this._okViewers.indexOf(app.viewerType) >= 0)  && (this._okOSs.indexOf(app.platform) >= 0)){
       // hide Error warning
        this.getField(this._errorForm).hidden = true;
        return true;
    } else {
        this.getField(this._errorForm).hidden = false;
        if (this._okOSs.indexOf(app.platform) < 0) {
            app.alert({
                cMsg: "Only Microsoft Windows and Apple MAC Adobe Readers/Acrobat supported.\n\nThis system Reported OS as " + app.platform,
                nIcon: 3,
                nType: 0,
                cTitle: "OS Not Supported"
            });
        }
        return false;
    }
}

if (this._checkViewer_SREF()) {		// this will run at document startup
    this._openingMessage_SREF();
}

 

The problem is when I combine these two forms from .  An error message to "An incorrect structure found in the PDF file"

image.png

 

This error happens when I addia file from  the "Page Thumbnails" > "Insert File" (Shift+Ctrl+I).

image.png

 

The error does not occur when I use the "Combine Files" tool.

 

Thank you for any guidance you might be able to offer.

 

Alex Lindberg

Topics

Acrobat SDK and JavaScript, PDF forms

Views

34

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
Sep 03, 2020 0
Most Valuable Participant ,
Sep 03, 2020

Copy link to clipboard

Copied

Maybe both files could have the complete set of document level functions. Still, nobody is expected to be combining fillable forms. The field name clash puts off 99%. 

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...
Sep 03, 2020 0
New Here ,
Sep 03, 2020

Copy link to clipboard

Copied

Both documents have 'Document level" JavaScripts.  

 

It would be nice if there was a prompt or preference setting that would control how JavaScripts would combine, both at the document and field level.

 

I the case of my forms, there are no field name collisions.

 

 

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...
Sep 03, 2020 0