These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Deleting pages question

lnail
Registered: Apr 18 2008
Posts: 51
Answered

I have an 88 page form that I would like to add the JS Doc method deletePages() on the Submit button to rid the form of unnecessary pages before submitting.

The parameters of the deletePages are nStart and nEnd. For example:

this.deletePages({nStart: 1, nEnd: 3});

The pages that I want to delete are mixed across the document. Is there a proper way to write this script so that it will delete pages within other pages, not just in a row of pages?

I have thought of just using multiple instances of deletePages(), one after the other, but am curious if anyone here knows that if I did do that, would I have to use the exact base 0 page numbers from the beginning of the script, or would I have to adjust the base 0 page numbers for each instance of deletePages that I use, even though they will be ran one after the other?

L Nail

YES! I can do that.

My Product Information:
Acrobat Pro 8.1.2, Windows
lnail
Registered: Apr 18 2008
Posts: 51
OK. I figured it out.

Yes. The base 0 page numbers change with each instance of deletePages() used. It took nine instances of deletePages() to work, but it works, and that's all that matters.

YES! I can do that.

wingateg3
Registered: Jan 7 2008
Posts: 25
Can you post your sequence...

I am running into problems deleting the last page in a document...

For example, I have a 29 page doc, so here are my sequences to delete all but page 8...

this.deletePages({nStart:8, nEnd:28});
this.deletePages({nStart:0, nEnd:6});

...keeps throwing an internal error, but works fine as long as I don't delete the last page...for example:

this.deletePages({nStart:8, nEnd:27});
this.deletePages({nStart:0, nEnd:6});

...this works great besides leaving the last unwanted page...
any ideas? Thanks in advance...
lnail
Registered: Apr 18 2008
Posts: 51
wingateg3,

Are you using at least Acrobat v6?

Since you are trying to delete page nine and ALL pages thereafter, then simply don't put the "nEnd" in your script.

this.deletePages({nStart:8,});
this.deletePages({nStart:0, nEnd:6});

In my situation, I didn't need to delete the last page, so my script wouldn't be much help to you.

I could very well be wrong. I still have a lot to learn myself. :D

lnail

YES! I can do that.

wingateg3
Registered: Jan 7 2008
Posts: 25
using

this.deletePages({nStart:8});

just deletes the 9th page with no ending on the range.

Thanks for the quick response though...I think I will have to add a last page that is hidden or something...time to dig around some more...thanks again

Edit: Using Acrobat Pro 8
lnail
Registered: Apr 18 2008
Posts: 51
I know that it's base 0, but have you tried putting the nEnd as the actual last page number, non-base 0?

this.deletePages({nStart:8,nEnd:29});

Here is what the JS API says:

[b]deletePages[/b]

Deletes pages from the document. If neither page of the range is specified, the first page (page 0) is deleted. [i]See also insertPages, extractPages, and replacePages.[/i]

[b][i]Note: You cannot delete all pages in a document; there must be at least one page remaining. (Acrobat 6.0): Beginning with version 6.0, this method deletes spawned pages from within Adobe Reader for documents with forms usage rights enabled. [/i][/b]


[b]Parameters[/b]

Example: Delete pages 1 through 3 (base 0), inclusive.

this.deletePages({nStart: 1, nEnd: 3});

nStart (optional) The 0-based index of the first page in the range of pages to be deleted. The default is 0, the first page in the document.

nEnd (optional) The last page in the range of pages to be deleted. If nEnd is not specified, only the page specified by nStart is deleted.

YES! I can do that.

wingateg3
Registered: Jan 7 2008
Posts: 25
didn't work...still errors out...
lnail
Registered: Apr 18 2008
Posts: 51
sorry I couldn't be of more help.

YES! I can do that.

wingateg3
Registered: Jan 7 2008
Posts: 25
OK,

Here's a fix...not sure how "correct" it is, but it works for my purpose...

This is all part of a trusted function that is called from a menu item...

{
var t = this.createTemplate({cName:"LastPage", nPage:28});
t.hidden = true;
}

this.deletePages({nStart:8, nEnd:27});

this.deletePages({nStart:0, nEnd:6});

works like a champ...end up with only page 8 displayed...
lnail
Registered: Apr 18 2008
Posts: 51
alright.. glad you got it.. I spent a bit of time trying to find an answer for you.. I know how hard it can be when you hit a snag, just trying to find the right answer.

lnail

YES! I can do that.

wingateg3
Registered: Jan 7 2008
Posts: 25
Thank you much for your help...

This isn't a solid fix, since it is not really deleting the last page, but just hiding it...

I would still be interested if anyone has an idea why it won't delete the last page...my understanding of the process is that there must be one page remaining, so it seems like Page 8 would satisfy that requirement...
wingateg3
Registered: Jan 7 2008
Posts: 25
Thanks so much for the help with this...my internal error I was receiving was completely unrelated to "this.deletePages" function. I had some hidden fields on the last page that were being referenced by a saveAs function...rookie mistake

EDIT: Thought I would post what I finally went with...this allows all pages except the one you want to be deleted regardless of the total number of pages...helps in case someone appends a page to the end...

this.deletePages({nStart:8, nEnd:this.numPages-1});

this.deletePages({nStart:0, nEnd:6});