Spawned controls perform poorly and crash
I'm working with PDF output from Taxport, 10,000 pages with hundreds of documents concatenated for printing; document length within the file can vary from 4-18 pages. I need to add barcodes to the individual documents within the file for the print vendor to stuff the envelopes accurately. Taxport can add text and a counter on page one of each document, but not the barcodes. Taxport also can't add blank pages as needed for duplex printing, so this 10k page document includes blank pages between every content page.
I have this script that worked 18 months ago for blocks of 450 pages. Now, it's hanging and not completing the job after just a few pages.
I have code to add required blank pages and that is working fine.
Then I add a duplicator:
- Add a page before page 1. On it:
- Paste a random fillable field from any other document (otherwise Acrobat will try to find fields in your current document)
- Created a data matrix barcode (ckick ok for the warnings)
- remove the reference line from the last tab of the Barcode dialog
- Remove the random fillable field added above
- Use tool Page Template on the new page 1.
- To establish the template page --> search the tools for "Page Templates"
- Name the page 01 and Add.
Next I add this to the Calculation of my data matrix barcode.
var docid = "";
var sequence = "";
var p = event.target.page;
console.println("on page " + p);
var wc = this.getPageNumWords(p);
if (this.getPageNthWord(p,wc-4) == "Page") {
var hp = p;
while (sequence == "") {
for (var n = this.getPageNumWords(hp) - 1; n >= 0; n--) {
if ((docid = this.getPageNthWord(hp, n)).slice(0,5) == "DOCID") {
sequence = docid.slice(-1);
break;
}
}
if (sequence == "") hp = hp - 1;
}
var pageNumber = this.getPageNthWord(p,wc-3);
var pageTotal = this.getPageNthWord(p,wc-1);
var x = ("0" + pageNumber).slice(-2);
var y = ("0" + pageTotal).slice(-2);
var vendorCode = x + y + sequence;
event.value=vendorCode;
console.println("setto " + vendorCode);
}
Then I run this in the console-->
for (var mp = 1 ; mp <10000 ; mp++) {if (mp%2 == 1) {this.getTemplate("01").spawn(mp,true,true) ;}}
My console output indicates that it's calculating every barcode every time it adds a barcode. (It prints "on page 1" then "on page 1 on page 3" etc, so it will take O(n^2) time. It usually crashes before it can finish. Can I prevent it from calculating until the end?
Thanks,
Chris
