Help Needed: Security Settings Preventing JavaScript from Appending Embedded PDF in Acrobat Pro
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:
Embedded the PDF:
- I have embedded the PDF file (anotherDocument.pdf) into the main PDF using Adobe Acrobat Pro.
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."
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!