Avg. Rating 4.0

Problem

The amount of data you need to encode into a barcode from your form can vary. How can you automatically increase the number of barcodes on your form to capture all of the data?

Solution

Dynamically increase the number of barcodes, according to the amount of data present.

Detailed explanation

The script below allows for a variable amount of data to be safely captured to a barcode,
or a series of barcodes.

The number of barcode graphics created will depend on the size of the data.

Every call to this function will erase the current instances of barcodes in the specified subform and replace them with new barcodes reflecting the data last passed to the createbarcodes() function

Requirements

This script requires JavaScript to be active in the Reader/Acrobat environment.

The PDF form must be saved as a Dynamic PDF from the Save/Save As... dialog for the barcode to update when the script is run.

The instantiable subform must have its content flowed and allow page breaks
The instantiable subform must have its property under Object > Binding : "Repeat Subform for Each Data Item" set to true/ticked
The instantiable subform must have a minimum occurrence of 1, an initial count of 1, and have its presence set to "Hidden"
The instantiable subform must contain a Dynamic Barcode object of the type and size desired, named "Barcode", with the Custom Script checkbox ticked, and the script inside the barcode commented out/deleted

The page containing the instantiable subform must be flowed, to allow for correct page breaking

Arguments

(string) data
    the raw data string to be encoded to the barcode

(subform) instform
    the instantiable subform, which contains a Dynamic Barcode object called "Barcode"

(integer) maxByteSize
    the maximum number of bytes that the barcode diagram can hold
    (around 800 for PDF417 barcodes, for example)

 

/** Version 2009.10.14 / R2 */

function createbarcodes(data, instform, maxByteSize) {
    // remove all current barcodes
    
    // having a min count of zero causes the instantiable subform
to be undefined.
    // Workaround: have a minimum of 1, hidden and leave it
there.....
    while(instform.instanceManager.count > 1) {
        instform.instanceManager.removeInstance(1);}
    
    // Having no data in the field causes (field).rawValue to be
null. Catch this
    if(data == null) {data = "";}
    
    // start
    var size=0;
    var start=0;
    for (var i=0;i<data.length;i++){// iterate over every
character
        // determine the number of bytes coding for the character
        var bval = data.charCodeAt(i);
        size += (bval-(bval % 255))/255 + 1; // determine the byte
size from the char value
        
        if (// if reading complete, or maximum data capacity
reached
            size >= maxByteSize
            ||
            i >= data.length-1
        ) {
            // add instance of instantiable subform
            var instance = instform.instanceManager.addInstance(1);

            
            // get the currently read section and put in barcode
            instance.Barcode.rawValue = data.substring(start,i+1);
            // the instantiable subform starts hidden, so that the
initial empty barcode never shows
            instance.presence = "visible";
            
            // initialize for next iteration
            start=i+1;
            size = 0;
        } // else go to next char
    }
}

 

multi-barcode_20091014r2.pdf.zip
[Example implementation]

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes