Copy link to clipboard
Copied
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:
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
Copy link to clipboard
Copied
Why not just add the barcode fields programatically?
Then add the calculation script at the end, why use the templates?
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#addfield
To be honest, I haven't used barcodes in a while, so if there is some reason it can't be done programatically, then put the barcode on a dynamic stamp and apply the stamp to every page.
Does the barcode need to be different for every page? If not then you can used a flattened image in either a template like you are doing or in a stamp. Or in a watermark.
Copy link to clipboard
Copied
Barcodes are like cars. You have simple ones, fast ones, complicated ones … The simplest barcodes are fonts, so you simply write something in a specific font on your document. Easy. It's more complex with QR codes or the like.
Copy link to clipboard
Copied
You should disable calculating before spawning the pages, then enable it afterwards, like this:
this.calculate = false;
// code to spawn pages goes here
this.calculate = true;
this.calculateNow();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now