Copy link to clipboard
Copied
PLEASE HELP!!!!
So, I have this State form that is distributed as an XFA document (original document and my version attached). As I understand, XFA format has always been a headache to developers. So here's where I am, I've recreated the document using Print to Abode PDF. Finally, I've added a button to run some javascript (pasted below).
I've tried everything I've come across in searched articles, but repeatedly get the message - NotAllowedError: Security settings prevent access to this property or method. I've checked the Document Security Properties and all say 'Allowed'. Oh, almost forgot to mention, I CAN manually perform insert pages from a file going through the menu. I'm open for any/all suggestions.
Thanks a million in advance.
app.trustedFunction(function () {
app.beginPriv();
this.insertPages ({
nPage: -1,
cPath: "/c/temp/AdditionalMember.pdf",
nStart: 4
});
app.endPriv();
});
app.alert("Additional Member Page Added!");
Copy link to clipboard
Copied
You can't define the trusted function in the button. That would defeat the whole point of having code run from a privileged context. The (generic) function for inserting pages must be placed in a .js file in a specific folder on the local computer for it to work. You then call it from the button.
Copy link to clipboard
Copied
Hi, Try67;
Thanks a ton! This is a good start and I am going to give it a try. However, I can't find any examples of how to make the call to the javascript file from a button. Any references/examples you can point me to would be greatly appreciated.
Thanks
Copy link to clipboard
Copied
You put the code in a (named) function, and then call that function from the button.
So in the .js file you have something like this:
function myTrustedInsertPages(doc, page, docPath, startPage) {
// Place trusted code here
}
And then you call it like this:
myTrustedInsertPages(this, -1, "/c/temp/AdditionalMember.pdf", 4);
Copy link to clipboard
Copied
Hi, Try67;
Yes, this is exactly what I did try. (I believe). I created a .js file and saved it under - C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts. The file simply has this:
function trustedAddMember(oDoc){
app.beginPriv();
this.insertPages ({
nPage: -1,
cPath: oDoc,
nStart: 4
});
app.endPriv();
}
Then, for my button on document. I added this javascript:
trustedAddMember("/c/temp/AdditionalMember.pdf");
app.alert("Additional Member Page Added!");
But, yet, I still get this message:
NotAllowedError: Security settings prevent access to this property or method.
App.beginPriv:2:Field Add Member:Mouse Up
As, I previously mentioned, I could manually insert a page, and looking at the document properties, there is no security in security method, and everything says "Allowed".
If it helps, I'm using Adobe Acrobat Pro 2023. I was first attempting to use .duplicate(), but discovered that was either deprecated or only used in another Adobe product. I feel like I'm close, but just missing something somewhere. Also, I have a button on the page for deleting a page. It works fine, and only uses this:
if (this.numPages > 10)
{
this.deletePages({nStart: 4, nEnd: 4});
}
Copy link to clipboard
Copied
Since you hard-coded the path, you need to pass a reference to the Document object, like this:
trustedAddMember(this);
And in the trusted function change this:
this.insertPages ({
To:
oDoc.insertPages ({
Copy link to clipboard
Copied
Sorry to trouble you, Friend. But, I've been developing 25+ years, and I have pdf forms working just fine in the application to populate fields in the form from the database. But because the original document has this button to Add/Remove a member (essentially a page, or maybe even a template), I'm trying to replicate that functionality as I'm sure it will be needed.
So, now I have this on the button:
trustedAddMember(this);
app.alert("Additional Mmber Page Added!");
and this in my .js file:
function trustedAddMember(oDoc){
app.beginPriv();
oDoc.insertPages ({
nPage: -1,
cPath: "/c/temp/AdditionalMember.pdf",
nStart: 4
});
app.endPriv();
}
I feel like I'm so close, but I continue to get the same error:
NotAllowedError: Security settings prevent access to this property or method.
What am I missing? Thanks a ton in advance.
Copy link to clipboard
Copied
Use this code as the folder-level script:
function trustedAddMember(oDoc){
myTrustedInsertPages(oDoc, -1, "/c/temp/AdditionalMember.pdf", 4);
}
myTrustedInsertPages = app.trustedFunction(function(doc, vPage, vPath, vStart) {
app.beginPriv();
doc.insertPages({nPage: vPage, cPath: vPath, nStart: vStart});
app.endPriv();
});
Copy link to clipboard
Copied
Hi, try67;
So, I've tried your latest suggestions. I hope this new error message indicates progress, although I'm still not getting the page inserted. Again, I check the document security and there is none.
RaiseError: Access denied.
A google search suggesed I uncheck Enable Protected Mode at startup (Preview). But when I give that a try and relaunch Acrobat and try it again, then I get this message:
TypeError: Invalid argument type.
Doc.insertPages:7:Field Add Member:Mouse Up
===> Parameter nStart.
Copy link to clipboard
Copied
Make sure you provide a correct page number for the nStart parameter. Remember that page numbers are zero-based in JS, so if the file has 4 pages you can't specify it as 4...
Copy link to clipboard
Copied
Absolutely. However, the document is 10 pages long. So, Page 5 shoud fit. 😞
Copy link to clipboard
Copied
Withing seeing the actual files I'm afraid I can't help you further. I tested the code on my local machine and it worked fine.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I think you got the nStart and nPage parameters mixed up. nPage is the page number in the original document ("T-3 CSHCN Program App ENGLISH_20220930_ECI.pdf", in this case), where you want to insert the new pages. nStart is the page number from the target document ("AdditionalMember.pdf") which you want to insert into the original document. You specified them the other way around.
Copy link to clipboard
Copied
Voila!!!! try67, My Man, you ARE The Man!!! That worked. Thanks a ton. Whenever you're in Dallas/Fort Worth area, I owe you lunch. Enjoy your day, Bro!
Copy link to clipboard
Copied
A Texas lunch sounds pretty good, but I'm afraid I'm an ocean and a continent away... 🙂
Glad to hear you were able to get it working, though!
Copy link to clipboard
Copied
Just enable this option:
Preferencies -> General -> Javascript -> Enable menu item javascript execution privileges.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more