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

NotAllowedError Security settings prevent access to this property or method

Community Beginner ,
Oct 06, 2023 Oct 06, 2023

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!");

TOPICS
Edit and convert PDFs , JavaScript
11.0K
Translate
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 ,
Oct 06, 2023 Oct 06, 2023

 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.

Translate
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 Beginner ,
Oct 09, 2023 Oct 09, 2023

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

Translate
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 ,
Oct 10, 2023 Oct 10, 2023

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);

 

Translate
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 Beginner ,
Oct 10, 2023 Oct 10, 2023

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});
}

 

 

Translate
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 ,
Oct 10, 2023 Oct 10, 2023

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 ({

Translate
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 Beginner ,
Oct 13, 2023 Oct 13, 2023

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.

Translate
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 ,
Oct 13, 2023 Oct 13, 2023

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();
});
Translate
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 Beginner ,
Oct 16, 2023 Oct 16, 2023

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.

 

Translate
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 ,
Oct 16, 2023 Oct 16, 2023

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...

Translate
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 Beginner ,
Oct 17, 2023 Oct 17, 2023

Absolutely.  However, the document is 10 pages long.  So, Page 5 shoud fit. 😞

Translate
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 ,
Oct 17, 2023 Oct 17, 2023

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.

Translate
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 Beginner ,
Oct 17, 2023 Oct 17, 2023

Here is my file I'm testing with and the page I'm attempting to insert.  The javascript is in this message thread.  

 

Thanks

Translate
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 ,
Oct 17, 2023 Oct 17, 2023

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.

Translate
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 Beginner ,
Oct 18, 2023 Oct 18, 2023

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!

Translate
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 ,
Oct 18, 2023 Oct 18, 2023

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!

Translate
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 ,
Nov 26, 2024 Nov 26, 2024
LATEST

Just enable this option:

Preferencies -> General -> Javascript -> Enable menu item javascript execution privileges.

Translate
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