When I use batch processing and javascript to merge a PDF to different background PDFs (I have a large PDF of 4000 pages that contains 1000 documents, each that merges to a specific background PDF), it takes a very, very long time. I have to break up my original PDF into much smaller PDFs and run the batch on each PDF. Then I combine the PDFs into one large PDF to send off for production. Is there a way that I can speed up the batch process so I don't have to split and recombine? Here is the code:
var ckWord, numWords, pgNum, mastVersion;
for (var p = 0; p < this.numPages; p++)
{
j=0;
mastVersion = " ";
ckWord = " ";
while (mastVersion != "MASTHEAD")
{
mastVersion = this.getPageNthWord(p,j).substring(0,8);
//app.alert("mastVersion="+mastVersion);
j++
}
mastVersion= this.getPageNthWord(p,j-1).substring(0,9);
//app.alert("mastVersion="+mastVersion);
j=0;
while (ckWord != "MERGEKEY")
{ckWord = this.getPageNthWord(p,j).substring(0,8);
//app.alert("ckWord="+ckWord);
j++
}
if (ckWord == "MERGEKEY")
{
pgNum= this.getPageNthWord(p,j-1).substring(8,11);
//app.alert("pgNum="+pgNum)
if (mastVersion == "MASTHEAD1")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_WEB_12pgr_July31.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD2")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_PRINT_12pgr_July31.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD3")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_WEB_8pgr_PMS_July31.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD4")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_PRINT_8pgr_July31.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD5")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_PRINT_4pgr_July31.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD6")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_WEB_FRE_12pgr_Aug10.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD7")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_WEB_FRE_8pgr_Aug10.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
if (mastVersion == "MASTHEAD8")
{
this.insertPages(p, "/C/Premier Mastheads Testing/Premier_PRINT_FRE_4pgr_Aug10.pdf", pgNum-1);
this.createTemplate("onepage", p);
op = this.getTemplate("onepage", p);
op.spawn(p+1, true, true);
this.deletePages(p);
this.removeTemplate("onepage");
}
}
}
Since you already know what file is the background for which page, you could write a script to automate the whole thing. No batch process necessary. Run it from a folder level script.
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script