• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
6

Spawned controls perform poorly and crash

New Here ,
Jan 26, 2024 Jan 26, 2024

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:

 

  1. Add a page before page 1. On it:
  2. Paste a random fillable field from any other document (otherwise Acrobat will try to find fields in your current document)
  3. Created a data matrix barcode (ckick ok for the warnings)
  4. remove the reference line from the last tab of the Barcode dialog
  5. Remove the random fillable field added above
  6. Use tool Page Template on the new page 1.
  7. To establish the template page --> search the tools for "Page Templates"
  8. 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

 

TOPICS
JavaScript , PDF , Print and prepress

Views

228

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2024 Jan 26, 2024

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. 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2024 Jan 27, 2024

Copy link to clipboard

Copied

LATEST

@Thom Parker ,

 

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.

ABAMBO | Hard- and Software Engineer | Photographer

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2024 Jan 27, 2024

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();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines