Home > Programming > id_barcode – a barcode maker for Adobe InDesign

id_barcode – a barcode maker for Adobe InDesign

March 4th, 2011

id_barcode is multiple things. It’s an example of writing structured, modular code for an InDesign plugin. It’s a demonstration of test-driven development for producing InDesign plugins. It also makes barcodes.

InDesign barcode maker

First off, this is a barcode maker for InDesign. It’s fairly simple – just put in your ISBN, and choose the font for the ISBN and for the numbers under the bars.

The script file is available to download here. If you don’t know how to install an InDesign script, see these instructions on InDesign Secrets.

Here it is:

id_barcode dialog

and this is what the barcode looks like:

Pretty wild.

Writing modular InDesign plugins

I split id_barcode across four files:

Really barcode_main.js should be split up into two files, one for the GUI and one for rendering the barcode.

Each part of the code does one thing. barcode_library doesn’t know anything about InDesign, all it does is produce a data structure giving the relative bar widths. The GUI code doesn’t contain any logic, it just lets the user enter the relevant details. Then the rendering code takes the barcode from the GUI, uses the library to get the bar widths, and draws the barcode with these widths and the fonts selected by the user.

Because I wanted to make the plugin easy to use, I wrote a shell script to concatenate the relevant JavaScript files and remove the #import lines. This was pretty straightforward.

Test-driven development

I’ve been reading Test-Driven JavaScript Development – an excellent book. I used some of the basics from that to construct a very basic testing framework, contained in barcode_test.js. Also in that file are a number of tests used to ensure that barcode_library.js was doing the right thing. Every time I changed something, or refactored, rather than checking to see if the barcodes still came out correctly I could just run the tests and get instant feedback. I haven’t written tests for the rendering code, but that would be a good next step.

Next steps

So far this plugin is very basic. You can’t customise anything apart from the fonts, so if you standardly use a different barcode design you’d need to do manual work to each barcode. The error handling’s a bit rubbish as well. If I make it more customisable, I think it would be worth test-driving the layout changes. The most important thing is to write a test that ensures the bars are all the correct width. I’d then have to start delving further into InDesign’s object model, which is a bit of a mess. We’ll see.

If anybody’s interested in contributing you can fork me on github!

Categories: Programming Tags: ,
  1. March 13th, 2011 at 11:00 | #1

    I repost Barcode Maker on my blog http://adobeindesign.ru/2011/03/13/indesign-barcode-maker-script/, many thanks!

  2. March 13th, 2011 at 17:11 | #2

    Excellent, thanks!

  3. UserID
    March 24th, 2011 at 23:48 | #3

    WON der full! Thank you!

  4. December 19th, 2012 at 16:28 | #4

    Meadows Publishing Solutions has released an updated version of their 2D Bar Code Module for Adobe InDesign, with a free license option for producing QR Codes. This new software module is designed to generate QR Code, Data Matrix, and PDF417 two-dimensional bar codes directly in any Adobe InDesign document.

    To help introduce the product, Meadows is currently offering a FREE license of the new module, which is limited to the production of QR Codes. The free license can be obtained by visiting http://www.meadowsps.com/free2d

  5. January 14th, 2013 at 03:33 | #5

    Read the post recommended for the bar code maker in design. Sometimes need to convert barcodes in reports solution into PDF. And it is easy to insert bar codes in PDF now.

  6. January 5th, 2014 at 15:33 | #6

    Just desire to say your article is as astounding.

    The clarity to your post is just great and that i can assume you are an expert on this subject. Fine along with your permission allow me to grab your RSS feed to stay updated with impending post.

    Thank you 1,000,000 and please continue the gratifying work.

Comments are closed.