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

Remove & Spawned Pages

Community Beginner ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

I have a 2 page form with buttons. 2 of the buttons have the ability to spawn a new page when selected. If both of these buttons are selected then the form go from the initial 2 pages to a total of 4. My question is that I have a clear form button that when pressed I want any and all spawned pages remove to reset the form to the original 2 pages. When I enter the script below it will remove one of the 2 pages, but not both. What am I missing?

 

if (numPages > 2) {

this.deletePages(2, this.numPages-2);

}

TOPICS
Acrobat SDK and JavaScript

Views

2.2K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Apr 02, 2020 Apr 02, 2020

Votes

Translate

Translate
Community Expert ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Your script only deletes the third page.

 

if (numPages > 2) {this.deletePages(2, this.numPages-1);}

 

See : https://help.adobe.com/en_US/acrobat/acrobat_dc_sdk/2015/HTMLHelp/index.html#t=Acro12_MasterBook%2FJ...

Votes

Translate

Translate

Report

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 ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

Thanks JR, that worked like a charm. Stay safe.

 

Votes

Translate

Translate

Report

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
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Hej JR,

I want to followup on this question…

I was trying to delete a spawned page from my form in Acrobat Reader and it fails with the error NotAllowedError: Security settings prevent access to this property or method. 

What can be the reason? Is it beacuse my template page was spawned from a template to the first page before saving it to reader Extended PDF?

Should I spawn the page when opening the document in Reader?

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Acrobat Reader DC can only delete spawned pages.

Votes

Translate

Translate

Report

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
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Hi Bernd, I already read that… but when I try to delete a spawned page with javascript I still get that error 'NotAllowedError: Security' in a Reader Extended PDF…

I don't know what I'm doing wrong… Please have a look:

The ReaderExtended PDF: https://documentcloud.adobe.com/link/review?uri=urn%3Aaaid%3Ascds%3AUS%3A10a58e0a-de2d-49f4-87e4-2f1...

The original DC version: https://documentcloud.adobe.com/link/review?uri=urn%3Aaaid%3Ascds%3AUS%3A0e3da9f0-7194-44e3-8cdd-9d7...

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Use the document without reader extension.

Votes

Translate

Translate

Report

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
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Hej Bernd,

But I need to distribute the form to users with Acrobat Reader.

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

It will work in Acrobat Reader DC.

Votes

Translate

Translate

Report

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
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

I downloaded a Acrobat reader for testing and as you stated it works with the main version.

I thought that you always had to save the PDF as Reader extended ?

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Why does you thought this?

Votes

Translate

Translate

Report

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
Explorer ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

I'm in the Printing/Design world and I was told that otherwise the PDF could not be commented by clients for review.

 

Thnx Bernd for looking into this, but now I have another thing that I need to do is save the PDF without the first page to another filename.

We want to distribute a PDF that first has to be filled in by a Agent on page 1 of the form. He then get's a button to confirm and from that button the PDF is saved witout that first page. I had it working in a ReaderExtended version but now this does not work in a Acrobat reader when it's not ReaderExtended.

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Over the last 15 years, with every new version, Adobe has given Reader the ability to perform more operations without the Extensions (Rights).  Deleting non-spawned pages is not one of them, nor is extracting pages. 

 

So one option is to make the first page a spawned page, so it can be deleted before sending.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Extended Rights is no longer required since the release of Acrobat Reader XI (11), eight years ago (2012).

 

Older versions of Reader requires Extended Rights for Commenting and form filling, but they doesn't support spawning.

Votes

Translate

Translate

Report

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
Explorer ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

But why can't I then save the form with another name in Acrobat Reader?

Votes

Translate

Translate

Report

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 ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Nnormally you can "Save as" with all versions of Reader, whether PDF is activated or not.
The issue comes from elsewhere…

Votes

Translate

Translate

Report

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
Explorer ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

JR, You were right! It's the Security (Advanced) - Privileged Locations that was the cause.

Thnx!

Votes

Translate

Translate

Report

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 ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Ok so I have another question that pertains to the spawn and delete pages. Is there a way to spawn a certain number of additional pages from a selection in a drop down, that could be activated by a button selection. Here's what I am dealing with. I am making a form for quoting construction work. One of the options is to write a quote for multiple trips to the site. If the quote is for multiple trips, then I want to be able to add additional pages for each trip. 95% of our work is done in one trip, but we do have jobs where it can take up to 15 trip. So if I select the YES button for multiple trips, I can get it to spawn the additonal page, but is there a way for the Yes button to activate a drop down and whatever number is selected, than that many additonal pages would spawn to increase the length of the form.

 

I am in my infancy in learning scripts, so any help would be greatly appreciated.

Votes

Translate

Translate

Report

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
Explorer ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

J

Have a look at this PDF in the action of the button Add

https://documentcloud.adobe.com/link/review?uri=urn%3Aaaid%3Ascds%3AUS%3Ab11673e1-f9fc-4e3d-b1b8-eb5...

 

With the following code you will create a template from the first page.  

this.createTemplate({cName:"AgentSetup", nPage:0 });

 You can then view the templates in the tool Organize pages the templates…

Acrobat Pro DCScrnSnpz045.pngAcrobat Pro DCScrnSnpz046.png

Votes

Translate

Translate

Report

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 ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Yes, use a loop

here is some example code. it is not complete. I'm providing it as a guide.

 

var nNumOfPages = this.getField("PageCountDropdown").value;

var oPgObj = null;

var pgNum = ?;  // however you set the starting page number. 

if(nNumOfPages && !isNaN(nNumOfPages))

{

    for(var i=0;i<nNumOfPages;i++)

    {

        if(oPgObj)

             template.spawn(pgnum++, true, false, oPgObj);

        else

             oPgObj = template.spawn(pgnum, true, false);

    }

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

I can't seem to figure this one out. I need Scripts for Dummies apparently. My template is called Trip Pricing and it would spawn to the 3rd page of the form.

 

Votes

Translate

Translate

Report

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
Explorer ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

this.getTemplate("Trip Pricing").spawn(2, false, false);

Votes

Translate

Translate

Report

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 ,
Apr 06, 2020 Apr 06, 2020

Copy link to clipboard

Copied

I have that script already. I am trying to get it to spawn a number of pages from a selection in a drop down. For instance, if 10 is the selection in the drop down, than 10 additional pages would spawn.

 

Votes

Translate

Translate

Report

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 ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

var A = this.getField("dropdown").value;
if (!isNaN(A)) {this.getTemplate("Trip Pricing").spawn(A, false, false);}

Votes

Translate

Translate

Report

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 ,
Apr 08, 2020 Apr 08, 2020

Copy link to clipboard

Copied

LATEST

JR, I think "A" is the number of pages that need to be spawned.

 

So the loop I posted above is the correct way to go. But it is incomplete.

Three things need to be done to it.

1) Set the page number to 3

2) Set the dropdown name to the correct field name

3)add this code to the top

 

var template = this.getTemplate("Trip Pricing"); 

 

The code I provided is for testing. It is meant to be run from the console window, once you have added in the missing bits. As I've noted above. 

You'll find a tutorial on the Console window Here, Watch it:

https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro

 

There are a lot of moving parts here. This is a more complex issue than you think and we are missing the information needed to help. The first be is to be able to get the code for spawning multiple pages working. Don't even thing about putting it on one of the the dropdown events at this point, because there is another issue that needs to be thought out first. What happens if the user makes multiple selections in a row? 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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