The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,927 other followers

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).

Terry  Burton wrote a great barcode writer in pure PostScript for this, with a simple 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:

  1. Grab one EPS file from his site and search/replace the article number in it (do! it’s easy, read on)
  2. 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 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:

50 50 translate
2 2 scale
0 0 moveto <393737313437333936383031> <696e636c7564657465787420677561726477686974657370616365> ean13

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 EAN-13 parameters.)

Just put it through 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:

50 50 translate
2 2 scale
0 0 moveto (977147396801) (includetext guardwhitespace) ean13

So, this is the recipe of generating a bunch of EPS files for your EAN-13 article numbers:

  1. Download one sample EPS file from the
  2. 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.


5 Responses to “Generating EAN-13 barcode EPS files for your article numbers”

  1. 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?

  2. pikachu8 said

    This is so helpful, also did great favors to the issue I am facing with this barcode generator:

  3. Glad you find it useful :-)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: