Generating EAN-13 barcode EPS files for your article numbers
Posted by jpluimers on 2009/11/30
Recently, I needed a bunch of EPS files for EAN-13 barcodes (that’s the kind of barcodes European companies put on their products).
Edit 20250520: added Wayback/Archive links but some of the below links died, so at the bottom I have added additional pages and properly archived them.
[Archive] Terry Burton wrote a great barcode writer in pure PostScript for this, with a simple [Wayback/Archive] web front end to generate a barcode one at a time.
Actually, his tool can:
- Generate all kinds of 1D and 2D barcodes (EAN-5, -8, -13, Code 128, Code 39, Code 93, Data Matrix, GS1, ISBN and many may more)
- Generate the check digits where needed
Since most DTP packages favour EPS over PS, and I needed more than just a few of them, I went a bit beyond the one-at-a-time simple web front end.
In fact, the EPS file generated by Terry Burton’s web front end has just one variable: the article number.
Basically, there are two ways go generate a whole bunch of the barcode EPS files:
- Grab one EPS file from his site and search/replace the article number in it (do! it’s easy, read on)
- Encode the parameters in the URL on his web-site, and extract the link to the (random location of the) EPS file, then download the EPS file (don’t! costs a lot of time and burdens his web-server)
Let’s see how easy 1. is…
As a template, download the EPS for this [Wayback/Archive] EAN-13 barcode with article number 977147396801: in the linked page, just click on the barcode to save the EPS file.
An extract of the most important part of the EPS file is this portion almost at the end of the file:
gsave 50 50 translate 2 2 scale 0 0 moveto <393737313437333936383031> <696e636c7564657465787420677561726477686974657370616365> ean13 grestore
The article number 977147396801 is encoded in this string: 393737313437333936383031.
Basically, this is just hexadecimal ASCII encoding of the digits encoding for the barcode.
- 0 = ASCII 30
- 1 = ASCII 31
- 2 = ASCII 32
- 3 = ASCII 33
- 4 = ASCII 34
- 5 = ASCII 35
- 6 = ASCII 36
- 7 = ASCII 37
- 8 = ASCII 38
- 9 = ASCII 39
And the string “696e636c7564657465787420677561726477686974657370616365” is just the hexadecimal ASCII encoding of the parameters “includetext guardwhitespace” (On his site, Terry Burton explains about the [Wayback/Archive] EAN-13 parameters.)
Just put it through [Wayback/Archive] this decoder, then select “HEX to ASCII” and see the result.
I’m not sure why his web front end encodes using hexadecimal ASCII, as this piece works just as fine:
gsave 50 50 translate 2 2 scale 0 0 moveto (977147396801) (includetext guardwhitespace) ean13 grestore
So, this is the recipe of generating a bunch of EPS files for your EAN-13 article numbers:
- Download one sample EPS file from the
- Replace <393737313437333936383031> with (977147396801), where 977147396801 can be any 12 digit EAN-13 article number (the check digit with number 13 will be automatically calculated)
Hope this helps some people!
And thanks Terry for writing this fantastic tool.
Edit 20250520: links
- [Wayback/Archive] Barcode Writer in Pure PostScript has moved to a new subdomain.
- [Wayback/Archive] GitHub – bwipp/postscriptbarcode: Barcode Writer in Pure PostScript repository which I missed when writing the original blog post in 2009; the first commit is from 2008: [Wayback/Archived] Initial directory structure. · bwipp/postscriptbarcode@94169f8 · GitHub
- [Wayback/Archive] Free Online Barcode Generator – Create Print-Ready Barcodes new demo-page
- [Wayback/Archive] Magic – CyberChef: 393737313437333936383031 because the original decode site ceased to function and Cyberchef is so much better.
- [Wayback/Archive] Barcode Writer in Pure PostScript presentation
- [Wayback/Archive] postscriptbarcode/contrib/history/gem-muon-detector at master · bwipp/postscriptbarcode · GitHub
- [Wayback/Archive] GitHub – metafloor/bwip-js: Barcode Writer in Pure JavaScript
--jeroen






terryburton said
Regarding “I’m not sure why his web front end encodes using hexadecimal ASCII”
The hex encoding of the user-provided parameters guarantees that a malicious user of the website is unable to perform a PostScript injection attack to execute arbitrary PS code by escaping out of the string using a closing parenthesis, high-order byte or some other mechanism that I might otherwise neglect to guard against.
jpluimers said
Thanks a lot for the explanation. Since you render the PostScript you generate in order to create the bitmap images, you need to protect yourself, right?
pikachu8 said
This is so helpful, also did great favors to the issue I am facing with this barcode generator:
http://www.businessrefinery.com/excel-barcode/ean_13.html
jpluimers said
That’s of little use outside the Excel realm, and only one of dozens such paid libraries.
Terry Burton said
Glad you find it useful :-)
Terry