Tuesday, september 23rd, 2008

Barcodes and SVG

Warning: this entry is old. It may contain outdated information and may not reflect my opinion anymore.

Recently, I looked in possible solutions with a friend to generate “3of9 barcodes”. He wanted no dependency aside PHP itself, which excluded GD. The point is to print barcodes, not dump them to the screen, and so required a printable solution.

So I tought about sIFR: simply dump a good font (font 1, font 2, …) in a flash animation.

Of course that failed because of flash’s inerent inability to be printed (seems to be rendered at the browser’s screen resolution, then scaled).

The next thing I looked into, was SVG.

It actually works pretty well, in some browsers:

  • Google Chrome can’t show or print it: missing thin lines;
  • Internet Explorer requires Adobe’s SVG plugin, will be discontinued in January 2009, but it prints OK;
    • The bounding box has a fixed size and it’ll scale the render to fit it (keeping the proportions);
    • IE won’t scale correctly if we just specify the height or the width;
    • inlined SVG in IE is a pain (everything with IE is always a pain, so it’s consistent with itself);
    • There seems to be a new player: RENESIS, still in development, haven’t toyed with it;
  • Firefox is just perfect;
  • Safari is OK, but…
    • it seems to cache SVG in a very weird way;
    • the bounding box has a fixed size and it’ll clip the render to the box;
  • Opera is perfect on screen, but renders it in a web size then scales it when printing, and so is unusable.

Here’s a sample, with the styles “border: 1px solid #bbb;”, which will render OK in Firefox and Opera:

Each character has 9 lines of which 3 are thicks, plus a thin line at the end. The render I made has thick lines 3 times larger than thin ones, so to render “*GREYWORLD.NET*”, we have 240 units wide ( (3 * 3 + 7 * 1) * 15 chars).

The render is at “1.5cm” of height, corresponding to 40 units, so it’ll be 9.0 cm wide.

Here’s the same sample, with “height: 1.5cm; width: 9.0cm”, which should render OK in safari and IE:

Still missing Google Chrome… the barcode is totally unusable: the thin lines won’t appear. Anyway, I have other things to do so I won’t look into this.

You can get/see the code here, but be warned: nothing of this has been tested and this is mostly a quick hack, not proper coding.

The code is based on the description of 3of9 found on Russ Adams’ page about 3of9.

I’ve also looked at Pear’s Image_Barcode implementation (real well done, like all Pear libraries (sarcasm: it fills the canvas with white, then draw both black and white lines, and if the thick line is defined to be 3 pixels wide, it’ll draw 3 black/white lines in a row instead of a rectangle)).

Anyway, ultimately, this was rejected because of the dependancy on external plugins in IE (hey IE, SVG is standard, all the world supports it, why don’t you? And btw, why won’t you support CSS correctly? :P).

Posted at 10:29
 
Anglais seulement
Tags: barcode · php · svg

Comments

Comment RSS

First, the IE plugin for SVG is available at the following URL : http://www.adobe.com/svg/viewer/install/ and render well the example at your URL : http://greyworld.net/files/php-barcode-svg/barcode_svg.php

Second, I don't know what will be effort less.. installing the plugin in each IE which should use the system, or install GD and some others libraries on the server side to generate proper 3of9 bar code. Will see with the client.

Jean-Luc Cyr – Thursday, june 4th, 2009

Nice stuff indeed! You have provided very good information in details. It is really very informative.

Barcode Printer – Wednesday, october 7th, 2009

Really awesome information. thanks for sharing useful information.

Hire iphone developer – Thursday, october 15th, 2009

Google chrome inst as popular yet, so no need!

usb barcode scanner – Monday, december 21st, 2009

Drop a comment






Comments are formatted using Markdown. Basic syntax on Wikipedia.