Jump to content

[SOLVED] Barcodes - simple solution that seems to work only in IE


Edgewalker81

Recommended Posts

I was trying to make a very naive version of a barcode generator using code39 (it's based on just stretching out white and black 1x1 gifs in sequence)  The result is a correct barcode, and if I print it in IE it scans great.

 

The problem is printing (from apparently any computer to any printer) in FireFox garbles the code, almost like FF is just throwing out some images.  Suggestions?  Should I scrap this and go down the long road to php image generation?

 

Here's where I have my test:

http://www.edge-walker.com/barcode_tests/test.php

 

I don't want anybody wasting paper on my account :), but printing from firefox does give you something very different from what is on the screen.

 

Relevant code:

$black='<img src="b.gif" height='.$height.' width='.$width.' />';
$white='<img src="w.gif" height='.$height.' width='.$width.' />';
$encodings['0']="$black$white$black$white$white$black$black$white$black$black$white$black";
        // Encodings continue in that manner...

$html_string=$encodings['*'].$white;

$pos=0;
while($pos<strlen($text))
{
	$html_string.=$encodings[$text[$pos]];
	$html_string.=$white;
	$pos++;
}
$html_string.=$encodings['*'];

return($html_string);

 

 

Link to comment
Share on other sites

I have the same results as mentioned above, along with the validation recommendation.

 

However, I recommend generating the bar code as one image that can be printed.

 

Relying on HTML/browsers to render the bar code will mean that you might get it working now, but it could stop working upon the next update/fix FF/IE and different browser settings of different people could produce different results.

Link to comment
Share on other sites

I ran your generated code through the xHTML validator and it generated over 500 errors. If you fix the errors in the generated source it may fix the problems you're seeing.

 

BTW, it printed differently with FF than with IE7 on my machine.

 

Ken

 

Thanks for the help.

 

It was really just 500 instances of one error (being that I forgot to include quotes around my attribute values, which as far as I know doesn't affect the problem I was having).  I got XHTML validation by just inserting quotes where they ought to be.

 

In the end I got it to work by just making the images 10px x 10px, and it works in every browser I've tested since then. 

 

I'm a little intimidated by the orders of magnitude more complex a single-image solution is, but I plan to move in that direction as time permits.  Any suggestions?  I was thinking of working with php's GD2 libraries.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.