function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
brunol11brunol11 

"Interleaved 2 of 5" Barcode

Does anyone Know how to work with "Interleaved 2 of 5" Barcode font inside Salesforce?

 

Brazilian Banks works with this Bar Code and I´d like to know if someone did generate the bar code inside salesforce.

 

I did a VisualForce page and tagged the billing barcode number with <Font face="Interleaved2of5-Thin-Regular"> but i realized I can´t pass the barcode number directly into the font. It has to be changed in other char sequel and that´s what I don´t figure: How to build this char sequel and what characters do I have to use?

 

Any ideas? 

 

Thx a lot in advance

Best Answer chosen by brunol11
brunol11brunol11
Wow. almost 5 years. lol.
I believe only Brazil uses this barcode.
I´ll post my own answer to me:
Create it via JavaScript!

First draw 4 images, White (Width: 1 and 2 pixels) and Black (Width: 1 and 2 pixels). Fit the best height you may need for the images. Put it on your Static resources.

The "code", or - better - the barcode, will come from your controller.
 
<apex:page Controller="CarnetCriado" readOnly="True" showHeader="False" sidebar="False" renderAs="html" >

<apex:form id="Barcode" title="Clique 2x na página para IMPRIMIR" ondblclick="window.print()">
<apex:repeat value="{!BoletoCriado}" var="Boleto" id="Repetidor" >

Here is the JS. You can save it at your VisualForce Page or at your Static Resources.
Sugestions for improving the code will be always great!           
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"/>
    <script>
        $(document).ready(function() {
        // begin inception
        var bc = []; // String, 12
        var barcode = []; // String, 44
        var i2of5Par = []; // String, 110
        var i2of5Impar = []; // String, 110
        var stringImpar = '';
        var stringPar = '';
        var i2of5 = '';
        var decoder = '';
        var barcode =[];
        var controle = 0;
        var code = "{!Boleto.BarCode_CEF__c}";
        var vetor = [];
        var image = '';
        var url = '';
        var tamanhoVetor = ((code.length));
        bc[0]  = "00110";  //0 
        bc[1]  = "10001";  //1 
        bc[2]  = "01001";  //2 
        bc[3]  = "11000";  //3 
        bc[4]  = "00101";  //4 
        bc[5]  = "10100";  //5 
        bc[6]  = "01100";  //6 
        bc[7]  = "00011";  //7 
        bc[8]  = "10010";  //8 
        bc[9]  = "01010";  //9 
        bc[10] = "0000";   //start
        bc[11] = "100";    //stop
        if (tamanhoVetor == 44){          
            // Inserir o código de barras dentro do vetor barcode
            for (x=1;x<=tamanhoVetor;x=x+1){
                controle = x-1;
                barcode[controle] = parseInt(code.substring(controle,x)) ;
            }            
            // Capturar a sequencia de caracteres em posições pares do vetor barcode e inserir no vetor i20f5Par
            for (p=0;p < tamanhoVetor;p=p+2){
                for (q=0;q <= 9;q=q+1){
                    if(barcode[p]==q) {
                        i2of5Par[p] = bc[q];
                    }
                }
                // Montar a string dos caracteres em posição par
                stringPar = stringPar + i2of5Par[p];
            }          
            // Capturar a sequencia de caracteres em posições impares do vetor barcode e inserir no vetor i20f5Impar
            for (i=1;i < tamanhoVetor;i=i+2){
                for (j=0;j <= 9;j=j+1){
                    if(barcode[i]==j) {
                        i2of5Impar[i] = bc[j];
                    }
                }              
                // Montar a string dos caracteres em posição par
                stringImpar = stringImpar + i2of5Impar[i];
            }             
            // Criar String resultante da alternância dos caracteres de stringPar e stringImpar
            i2of5 = bc[10];
            for (pos=1; pos<=110;pos=pos+1){ //pos<=110
                decoder = stringPar.substring(pos-1, pos) + stringImpar.substring(pos-1, pos) ;
                i2of5 = i2of5 + decoder;
            }
            i2of5 = i2of5 + bc[11];
        }                
        //preenche o vetor com os caracteres de 'i2of5'
        for (i = 0; i <= 226; i++) { 
            vetor[i] = i2of5.substring(i, i+1);
        }                
        for (p = 0; p < vetor.length; p++) { 
            if(p%2 == 0 && vetor[p] == 0){image = '/resource/1439308179000/BC_Black_1px'}
            else{
                if(p%2 != 0 && vetor[p] == 0){image = '/resource/1439309801000/BC_White_1px'}
                else{
                    if(p%2 == 0 && vetor[p] == 1){image = '/resource/1439543472000/BC_Black_2px'}
                    else{
                        if(p%2 != 0 && vetor[p] == 1){image = '/resource/1439543508000/BC_White_2px'}
                    }
                }
            };
            for (r=1; r<=2; r++){
                url = '<img src="' + image + '" />';
                console.log(url);
                $('#{!Boleto.name}').append(url);
                $('')
            };
        };
    });
    </script>