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

Help Needed: Security Settings Preventing JavaScript from Appending Embedded PDF in Acrobat Pro

New Here ,
Jun 24, 2024 Jun 24, 2024

Copy link to clipboard

Copied

Hello Adobe Community,

I’m encountering an issue with Adobe Acrobat Pro while trying to append pages from an embedded PDF document to the existing PDF document using JavaScript. My goal is to have a checkbox in the main PDF that, when selected, will append all pages from an embedded PDF (anotherDocument.pdf) to the end of the main document.

Here’s a summary of what I’ve done so far:

  1. Embedded the PDF:

    • I have embedded the PDF file (anotherDocument.pdf) into the main PDF using Adobe Acrobat Pro.
  2. JavaScript Code:

    • I’ve added the following JavaScript code to the checkbox field to perform the append action:
     

    app.beginPriv();

    try {
    var checkbox = this.getField("checkboxName");
    if (checkbox.value !== "Off") {
    app.alert("Checkbox is checked, starting process...");

    var dataObjects = this.dataObjects;
    var embeddedFileName = "anotherDocument.pdf";
    var found = false;

    app.alert("Number of embedded files: " + dataObjects.length);

    for (var i = 0; i < dataObjects.length; i++) {
    app.alert("Checking data object: " + dataObjects[i].name);
    if (dataObjects[i].name === embeddedFileName) {
    found = true;
    app.alert("Found embedded file: " + embeddedFileName);

    try {
    var embeddedDoc = this.openDataObject({ cName: embeddedFileName });
    if (embeddedDoc) {
    app.alert("Embedded document opened successfully.");

    var numPages = embeddedDoc.numPages;
    app.alert("Number of pages in embedded document: " + numPages);

    for (var j = 0; j < numPages; j++) {
    app.alert("Attempting to append page " + (j + 1) + " of " + numPages);
    this.insertPages({
    nPage: this.numPages,
    cPath: embeddedFileName,
    nStart: j,
    nEnd: j
    });
    app.alert("Appended page " + (j + 1) + " of " + numPages);
    }
    app.alert("Pages appended successfully.");
    } else {
    app.alert("Failed to open embedded document.");
    }
    } catch (e) {
    app.alert("Failed to open embedded document due to security settings: " + e);
    }

    break;
    }
    }

    if (!found) {
    app.alert("Embedded file not found: " + embeddedFileName);
    }
    } else {
    app.alert("Checkbox is not checked.");
    }
    } catch (e) {
    app.alert("Error: " + e);
    }

    app.endPriv();

    Issues Encountered:
    • The script executes and confirms that the embedded document is found and opened successfully.
    • However, when attempting to append the pages, I receive an error stating: "Failed to open embedded document due to security settings."
  3. Security Settings:

    • I have added the document and its containing folder to the Privileged Locations in the Enhanced Security settings.
    • Enhanced Security has been temporarily disabled.
    • The document's security method is set to "No Security."

Despite these steps, the security settings still prevent the JavaScript from appending the embedded document’s pages. I am looking for guidance on how to properly configure the security settings or adjust the JavaScript to achieve my goal.

Any advice or solutions would be greatly appreciated. Thank you!

TOPICS
Create PDFs , JavaScript , PDF

Views

142

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
community guidelines
Community Expert ,
Jun 24, 2024 Jun 24, 2024

Copy link to clipboard

Copied

What is the EXACT text of the error message you're getting?

One recommendation I have is to keep a reference to the main doc as a variable, and not use the "this" keyword after you open the other document.

Also, numPages is already a property name of the Document object. It's not a good idea to use it as a variable name. Change it to something else, or don't use it at all and just access this property directly.

Votes

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
community guidelines
New Here ,
Jun 25, 2024 Jun 25, 2024

Copy link to clipboard

Copied

LATEST

Error message: "Failed to open embedded document due to security settings: NotAllowedError: Security settings prevent access to this property or method."

 

I've attached the PDF I am working on. I've only coded the first box by "Treasury Online Banking". I will try your recomendations and appreciate your help with this matter! 

Votes

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
community guidelines