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

Add Blank page after every 5 pages

DanB
Registered: May 8 2007
Posts: 34

I need to add a blank page after every fifth page so I wrote the javascript below. I want to run it as part of a batch process. It seems to choke at line 13 ( this.pageNum++ ). Has anybody have any ideas on how to fix this.

Thanks Dan

Code:
try {
var newName = this.path;
var blank = "blank.pdf";
var filename = newName.replace(".pdf","_Original.pdf");
this.saveAs(filename);
var x=1;
for(var i= 0; i <= this.numPages; i++){
if (x==5){
this.insertPages(0, blank);
x=1;
}
x++;
this.pageNum++ ;
i++;
}
}
catch(e)
{
app.alert(e);
}

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
I would suspect that the number of pages in the pdf is changing with each added page and the next page location to add the next blank page is also changing position. You should start with the last page of the pdf and work backwards. But you will have to save the original control variables. It also looks like all your inserted pages will be after the all the pages of the PDF.

From Acrobat's JavaScript Reference:

insertPages
Parameters: [nPage], cPath, [nStart], [nEnd]
Returns: Nothing

"...If nStart and nEnd are not specified, then the range of pages is for all
pages in the document...."

George Kaiser

DanB
Registered: May 8 2007
Posts: 34
I was thinking the nStart and nEnd parameters were the start and end of the pages to be inserted. My Blank PDF has only one page which is blank.

You may be right about the number of pages changing but that still doesn't explain why it crashes on "this.pageNum++" .

The actual error message states:
InvalidGetError: Get not Possible, invalid or unknown.

I even get this error when I just try to add an app.alert(this.PageNum).

Just a side note, I ran my script commenting out the problem line and it ran putting all the blanks after the first page. So I think my only problem is navigating to the next location which this.pageNum++ should do but doesn't.

Any other Ideas

Thanks
Dan
mohazia
Registered: Aug 12 2007
Posts: 3
ok, another example.
I'd like to add blank paper at the end of the pdf if its page number is odd.
because when i'd like to print the file in double sided paper it works perfectly.