Hello All,
I hope that someone can help me. I have a pdf document that contains 1928 pages that are a combination of 2 page packets. I need to insert a 10 page pdf after every 2 pages of the 1928 page pdf file. I have found multiple javascripts that can do this for inserting a blank page or just 1 page after a couple pages of a pdf. I think this code that I found in a previous post would work but I don't know how to modify it to meet my demands. If anyone could help me out I'd greatly appreciate it. So in summary I'm trying to insert a pdf into another pdf after every 2 pages until the end of the pdf. Thanks so much!
//test if number of pages is odd or even and exclude last from count if odd
var nmPages;
if(this.numPages%2==0)
{nmPages=this.numPages}
else
{nmPages=this.numPages-1}
//define path to pdf that will be inserted
var pth="/C/Users/<User>/Desktop/Blank.pdf"
//loop through pages and insert pdf after every even page
for(var i=nmPages-1;i>-1;i--)
{
this.insertPages({nPage:i,cPath:pth});
i--;
}
What happens when you try the code?
I haven't examined your code in detail, but I can tell it suffers from a problem common to "insert after/delete every Nth item" programs. The problem is that the action of inserting the page(s) will affect the pages in the document. So let's suppose the original document has pages A B C D E F ... and the new one has pages Z Y X W V U ...
The easy way to code this will go
A B C D E F ...
A B Z Y X W V U ...C D E F ...
A B Z Y Z Y X W V U ...X W V U ... C D E F ...
A B Z Y Z Y Z Y X W V U ...X W V U ...X W V U ... C D E F ...
and so on. To overcome this the easy way is to START AT THE END NOT THE BEGINNING.