djbryson has asked for the wisdom of the Perl Monks concerning the following question:

Trying to generate a PNG barcode. Script receives a random interger and converts to a barcode image. It also has to be 128A. I tried switching FNC1 to CodeA. I always get the same barcode image for my ouput. I need to encode the $text var right? I commented out use gd; because it generates the image either way.
use strict; #use gd; print "\nRunning Barcode... \n\n"; my $text = "333"; use Barcode::Code128 'FNC1'; my $object = new Barcode::Code128; $object->text(FNC1.'00000123455555555558'); $object->png($text); open(PNG, ">h:/perl/code128.png") or die "Can't write code128.png: $!\ +n"; binmode(PNG); print PNG $object->png("CODE 128"); close(PNG);

Replies are listed 'Best First'.
Re: help with Barcode::Code128
by gmargo (Hermit) on Nov 06, 2009 at 16:54 UTC

    I am confused about what you are looking for. You are setting the text to encode three different times, and generating two separate images, although you only save the last one to a file. That last one has a fixed string ("CODE 128") so you should be getting the same .png file each time.

    Here's some quick-n-dirty code that produces three barcodes with different integer texts, hope it can help you.

    #/usr/bin/perl use strict; use warnings; use diagnostics; use Barcode::Code128; my $times = 3; print "Running Barcode... encoding $times random integers\n"; my $object = Barcode::Code128->new(); $object->code('A'); # Enforce 128A? srand(0); # More interested in repeatability than randomness foreach (1 .. $times) { my $text = ""; # Make up a 10-digit decimal number $text .= "".int(rand(10)) foreach (1 .. 10); my $filename = "code128_".$_.".png"; open(my $png, ">", $filename) || die("Cannnot open $filename: $!") +; binmode($png); print $png $object->png($text); close($png); print "Text \"$text\" encoded in file $filename\n"; }

      I am using code128 for barcode creation through perl and the barcode will print in the pdf. It is working fine for normal characters. But it is not working for the characters إنِ... (Swedish). In pdf the characters are printing in the different charectors. Can any one give me any suggestion to work with swedish characters in barcode? Thanks in advance.

        Code128 says that swedish characters are not supported.