Skip to main content
May 26, 2024
Question

NotAllowedErro when calling newPage() or insertPages()

  • May 26, 2024
  • 2 replies
  • 2547 views

Dear all, 

Following this discussion on creating button to add/remove section in fillable form : https://community.adobe.com/t5/acrobat-discussions/button-to-add-remove-section-in-fillable-form/td-p/12634155

I started coding a similar form. I'm currently encountering the NotAllowedError when calling the newPage() functions or the insertPage() functions in my script. 

function test2() {
    global.doc = this;
    global.doc.newPage();
 }


Could anyone provide guidance ? 

Thanks in advance, 

This topic has been closed for replies.

2 replies

June 17, 2024

Hey @Bernd Alheit , @try67 , @Thom Parker ,

I'm still working on improving the code. I managed to have some things working: sections duplicated, deleted and bottom sections moving depending on duplication or deletion.

As I can't call the newPage() function from an unpriviledged location (eg. consequence of the duplicate button on the form), I decided to have natively a pdf with 10 blank pages on which the sections can be duplicated and the blank pages are deleted when the document is saved. 

Now I need to reproduce a pdf similar to the one from the original topic (eg.  the canadian form). 

It feels I can't create the PDF from the Adobe Accrobat "GUI" but only code it in order to be able to access the fields in my code. To tackle this, I've unsuccesfully tried using the getAnnot and the getField functions. 

To try other solutions, I started coding the PDF on my own. However, the PDF reference feels quite unclear sometimes. 

In order to create the PDF from code (sections, titles ect) I'm currently using the FreeText type of the Annotation object but to change the text color, I need to use the "span" properties and to change the text font, the span properties is not working, I need to change the defaultStyle of my annotation. 

I'm still reading the reference but could you kindly either send some good code example of pdf creation through the API so I can learn by reading or simply send the correct functions to call in order to create the texts, change their color and fonts because addAnnotation really seems a weird way but I haven't found anything else.

Thank you very much in advance,




Thom Parker
Community Expert
June 17, 2024

It sounds like you need some training.  

However, if you are going to get solutions from this forum, I would suggest posting questions on a single topic/issue. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
June 18, 2024

Thanks Thom, best training is practice, I'm glad to have found a challenge that pushes my knowledge while doing something I enjoy. 

If I had a single question, it would be: what's the best way to create a title with chosen  font and chosen color using the javascript API ? 

I know the question sounds really dumb ! But the single properties I've found related to this are:

- textColor: which needs to be added to a span object and then added to the richContents property of the FreeText annotation. 
- fontFamily: which needs to be used while modifying the defaultStyle property of the FreeText. This doesn't access local fonts: I've tried without success calling "Gotham-Bold" that I can choose from my acrobat drop down menu.

If you'd kindly direct me toward chosen documentation/reference pieces, give me some code to read or simply indicate the appropriate way of doing this, it would be amazing. 


Thanks

Bernd Alheit
Community Expert
May 26, 2024

Where do you use the function?

May 26, 2024

Dear Bernd, 

 

Thank you for your answer and for your intense activity on the forum. Your answers always provide very helpful guidance. 

I'm not very used to the terms, but if im correct, I don't think I'm camling the function from the folder level. 

I code my script on Visual Code Studio and then copy-paste it to the "app scripts" window in the javascript editor of Adobe Accrobat. 

May 27, 2024

Is the document protected or signed?

Try a other document.


I’m only working on blank documents.

 

It appears that using a new document permits the use of the newPage() function when called from the global function (as shown in my first post)

 

But when called from within another function  it replicates the notAllowedError.

 

Function test2() {

    global.doc.newPage(); // works

    try {

        global.doc.addScript( ´´ duplicate section’’)

            function duplicateSection() {

                try {

                    if (newSectionBottom < 0) {

                        global.doc.newPage(); // doesn’t work

                    }

                }

            }

      }

}