I have a barcode with a dimensions width: 162px and height: 50 px. When I print it in a A4 paper size,its dimension is 40 mm X 14 mmbut when printed in CR80 Cards(smaller paper size) it's size is 25mm X 9mm .

The barcode in the A4 paper is scanning well but barcodes in CR80 cards, doesnt. It is because the barcode size shrinks to fit the page and thus distorting the barcodes.

If and only if the barcodes is 40mm X 19mm in CR80 Cards it will be fine and be working(I assumed). So how will I know what dimensions (in px) , shall I command my printer to print to have the desired output?

  • Hi Alyssa, welcome to GDSE and thanks for your question. If you want to know more about the site, please see the help center or ping one of us in chat once your reputation is sufficient (20). Keep contributing and enjoy the site! – Vincent Apr 29 '15 at 9:57
  • How are you printing the barcode? Is the barcode a separate file and you are just printing from that file or are you placing the barcode in a document? If you're printing the barcode, then you can print a file/document so that is doesn't fit-to-page or shrink and print at 100%. – AndrewH Apr 29 '15 at 17:50
  • what is the barcode encoding? (3of9; code 128 etc) – Yorik Apr 29 '15 at 20:05
  • also: do you mean mm? – Yorik Apr 29 '15 at 20:10
  • @Yorik --> Thank you for asking me, it was really measured in mm and it was in in code39 encoding. I'll edit my post for you. – alyssaeliyah Apr 30 '15 at 0:30

A quick check suggests that the nominal size for some types (EAN-*) is "25.93mm in height and 37.29mm in width" and "they" suggest that you do not reduce that beyond 80% (20 x 29mm).

I didn't see anything specific to code39, but I suspect that your problem is merely that you have gone too far in reduction and the bars are too close together.

You don't mention the software you are using, but basically, place the image larger on the ID card. I have used 3of9 before and found that the height is less important than the width and bar spacing: The ones I used were probably about 3/8 inch high and 1.5 inches wide (about 9mm high x 38 mm wide).

If you have trouble fitting it with other information, place it large and crop the top. Experiment.

One more thing: code39 is a straight ASCII replacement scheme. This means that you can use a font. 12345abc becomes *12345abc* and you just set it using a 3of9 typeface like free 3of9. This makes sizing on the fly a non-issue and they can even be generated using a database report etc..

// Requires a font file on your server
$fR = 0; $fG = 0; $fB = 0;
$bR = 255; $bG = 255; $bB = 255;

$text_pad = 10;

$text = array(
    array('text' => '', 'size' => 19, 'left' => $text_pad, 'width' => 1, 'height' => 1, 'font_path' => ''),

$text[0]['font_path'] = realpath('./images/free3of9.ttf'); //give it a path relative to the calling script
$text[0]['text'] = strtoupper('*12345 bobs your uncle 6789*');  //simpe code39: ONLY 0-9 A-Z (caps) . - *
$text[0]['size'] = 60;
$text[0]['left'] = $text_pad;

$result = barcode_getdimensions($text[0]['text'], $text[0]['size'], $text[0]['font_path']);

$text[0]['width'] = $result['width'];
$text[0]['height'] = $result['height'];

//************ end configuration vars
function barcode_getdimensions ($a_string, $a_size, $a_font)    {
    $tmp['width'] = 0;
    $tmp['height'] = 0;

    if ($a_size == 0)   {   return $tmp;}

    $result = imageftbbox($a_size, 0, $a_font, $a_string);

    $tmp['width'] = $result[2] - $result[0];
    $tmp['height'] = $result[1] - $result[7];

    return $tmp;


//output the header. Any non-image output after this point will throw errors
header("Content-type: image/png"); 
header('Content-Disposition: inline; filename=barcode.png');

$image = imagecreatetruecolor(($text_pad * 2) + $text[0]['width'],($text_pad * 2) + $text[0]['height']);
$textcolor = imagecolorallocate($image,$fR,$fG,$fB);
$bgcolor= imagecolorallocate($image,$bR,$bG,$bB);
imagefilledrectangle($image,0,0,($text_pad * 2) + $text[0]['width'],($text_pad * 2) + $text[0]['height'],$bgcolor);
imagettftext($image, $text[0]['size'], 0, $text_pad, $text_pad + $text[0]['height'], $textcolor, $text[0]['font_path'], $text[0]['text']); 

imagedestroy($image);   // always destroy image

| improve this answer | |
  • I wish I had an image so that I can place it larger on my ID Card but unfortunately not. Im using a a jquery plugin to generate a barcode(not an image), which is a set of div's with a background color of black. barcode-coder.com/en/barcode-jquery-plugin-201.html – alyssaeliyah May 5 '15 at 9:21
  • Can u refer me a site that generates an image of a barcode, preferably a javascript or jquery plugin? – alyssaeliyah May 5 '15 at 9:21
  • Is this for your website? – Yorik May 5 '15 at 13:58
  • --> Yes, this is for my website. – alyssaeliyah May 6 '15 at 0:39
  • I would just use php to make an image, provided we are not talking about huge throughput. You would need to place a font file on your server so the script can access it, and then make sure you don't have illegal characters in the encoding. – Yorik May 6 '15 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.