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:
Embedded the PDF:
JavaScript Code:
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();
Security Settings:
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!
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.
Copy link to clipboard
Copied
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!