Skip to main content
Jongware
Community Expert
Community Expert
October 20, 2012
Question

[Ann] QR Code for InDesign CS4 and up

  • October 20, 2012
  • 9 replies
  • 26738 views

Ever needed to create a QR code? There are literally hundreds of free QR code generators on the web, but they all have the same drawbacks:

1. They typically deliver a PNG, either 'click here to download', or you have to drag it somewhere yourself.

2. It's typically an RGB image, so the cautious designer will start up Photoshop to convert it to a monochrome image.

3. .. so you get a file to store somewhere ..

4. ... and after seeing four of them you cannot remember which QR code said what ...

5. .... and, you cannot use such site in a batched environment (well, maybe some people can by building a proper URL, call the website, wait for a response, etc. I bet it's difficult for your average scripter.)

So I had a go on converting one of the existing Javascript solutions -- Patrick Wied's, in case you're curious -- into a construction fit for InDesign. All you have to do is download the zip: http://www.jongware.com/binaries/jw_qrcode.zip -- unpack it, and save the file "QRCode.jsxbin" in your local User Script folder. It ought to be compatible with InDesign CS4 and upwards, for both Mac and Windows.

When it appears in your Script Panel, you can double-click to run and

1. with nothing selected, it prompts for text and error recovery settings, and will place a proper monochrome TIFF bitmap of (approximately) a useful dimension in the center of your current page.

2. with an empty rectangle selected, the new QR code will be placed inside it.

3. with some text selected, the text field will be pre-filled with this.

4. With a QR Code selected which you created earlier using this same tool, the text field will contain the original text, and the quality setting will be retrieved. You can cancel the dialog if you only wanted to know what it said, or change the text or quality.

5. You can call this script from another script to perform batch operations. It accepts two required arguments, and one optional, in this order: text, Error Correction level (1-4), and optionally a destination rectangle to place it in:

app.doScript(new File(app.activeScript.path+'/qrcode.jsxbin'), ScriptLanguage.JAVASCRIPT, ["hello", 1, app.selection[0]], UndoModes.ENTIRE_SCRIPT, "Call QR Code");

6. Since it's a monochrome bitmap TIFF with enough resolution (at its default size it's 200 dpi), you can use the swatches palette to change the white or black parts to another color, or even make one transparent.

7. It's just a small file, and so I decided to always have it automatically embed. That way you can never loose it. The image first has to be created in a temporary file (default location: (Temp)/qrcode.tiff, where (Temp) is your local Temporary Files folder). If this fails for some of you (there always seem to be overly prudent IT professionals who seem to despise users storing files willy-nilly), I'll have to think of something else.

Note: this version only supports plain text mode, not numeric, alphanumeric, or Kanji. Text is converted to UTF-8; for the most common purpose -- web pages -- it should work normally.

Enjoy!

Based entirely on Patrick Wied's implementation of a basic QR Code generator. Patrick Wied dutifully notes

I do not guarantee any resulting QR code generations or detections, use this application at your own risk! - this project is just a study project (non commercial).

and so I advise to always check your generated code using a good QR Code reader.

This topic has been closed for replies.

9 replies

Participant
August 10, 2022

leider existiert diese zip nicht mehr. alternative für inDes CS4 ?

Participant
August 7, 2020

Merhaba bu scriptte eklediğim metnin yazı fontu ve bold italik gibi özelliklerini ayarlayabiliyormuyum.

Participating Frequently
May 3, 2014

Could you please send or post a .js file?! I would like to see what you have done with the code...

Participant
June 24, 2013

Nice work. You might find some useful code in the 'zend-framework-matrixcode-module', its used to generate vector eps and pdf QR codes on http://qrcode.littleidiot.be/.

Cheers

ThinkingThings
Inspiring
March 16, 2014

@Jongware,

Thank you for your contribution of this script and for all that you do for the Adobe community. This script works like a dream!

Kindest regards,

TT

Participant
March 18, 2013

I work for Meadows Publishing Solutions and we have released an updated version of our 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, we are currently offering a FREE license of the module which is limited to the production of QR codes. The free license can be obtained by visiting http://www.meadowsps.com/2Dforfree

Of course, our hope is that for clients that wish to automate the QR Code creation process via Excel spreadsheets or data files, they might consider a purchase of our DesignMerge variable data software, but this is certainly not a requirement.

Participant
February 24, 2013

To give back to community, here is the script to generate QR codes for business cards created by data merge

It reads text frames starting with MECARD:, empties them and places QRcode rotated 15 degrees counterclockwise. Enjoy!

var _d = app.documents[0];

var _allStories = _d.stories;

for(var nx=_allStories.length-1;nx>=0;nx--){

    var _storyAllTextFrames = _allStories[nx].textContainers;

    for(var mx=_storyAllTextFrames.length-1;mx>=0;mx--){

         _storyAllTextFrames[mx].select(); // change page

         if(_storyAllTextFrames[mx].contents.indexOf('MECARD:')==0){

             var obj = app.doScript(new File(app.activeScript.path+'/qrcode.jsxbin'), ScriptLanguage.JAVASCRIPT, [_storyAllTextFrames[mx].contents]);

             _storyAllTextFrames[mx].contents = "";

            var myScaleMatrix = app.transformationMatrices.add({horizontalScaleFactor:.7,

                verticalScaleFactor:.7,counterclockwiseRotationAngle:15});

            obj.transform(CoordinateSpaces.pasteboardCoordinates,AnchorPoint.centerAnchor, myScaleMatrix);            

            

             //obj.move ([_x,_y]);

         };

    };

};

here is a MECARD template for you:

MECARD:

N:<<Last>>,<<First>>;

TEL:<<Direct>>;

TEL:<<Mobile>>;

EMAIL:<<E-mail>>;

NOTE:<<Position>> at <<Company>>;

;

http://www.nttdocomo.co.jp/english/service/developer/make/content/barcode/function/application/addressbook/index.html

Colin Flashman
Community Expert
Community Expert
February 25, 2013

I like this use of the script that sergemca has provided. It doesn't perform the text-to-qrcode conversion on the fly as the document is being merged, but rather takes a merged file and applies qrcodes to any textframe that begins with MECARD: . Having said that, the script could also be applied to any large document that has textboxes with the MECARD: rule as outlined in the above post, a merged file is but one example.

Having said that, would a text frame that had a script label be more appropriate e.g. rather than the script hunting for any instance of a textbox with the words MECARD: in them, could an alternative be to look for textframes that have a similarly named script label? The advantage of this would be that the QRcode would not include the words "MECARD:" when made (or any other text trigger) that is in the script at the moment. What would have to change in the above script to accomplish this?

Nevertheless it is a brilliant script, well done.

Colly

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
Jongware
Community Expert
JongwareCommunity ExpertAuthor
Community Expert
February 25, 2013

Colly, the "MECARD" prefix is to indicate it is, in fact, a QR code containing MECARD data -- and not something like plain text, or an URL. See http://theqrplace.wordpress.com/2011/05/02/qr-code-tech-info-mecard-format/

So there is no point in leaving it out of the QR code ...

But of course the script can be adapted to your idea of using certain tagged frames only to grab, for example, only URLs. I have never used Data Merge; can it create separate text frames for 'certain' data items? If so, can you add a script label to these items? Then the script only has to loop over all text frames and examine its labels.

Oh and I agree, it's a very clever script! sergemca did *exactly* what I had in mind: build a framework around the QR code-code so it can be used with ease for custom solutions. (I also like that 15° rotation!)

Jongware
Community Expert
JongwareCommunity ExpertAuthor
Community Expert
October 22, 2012

Update:

I'm happy to report Patrick's code seems to hold up mathematically. I wrote an independent Reed-Solomon checksum calculator (*), and a QR code of 1,273 characters at Highest Quality, needing an additional 2,430 RS Error Correction bytes, appears to be fully correctly encoded.

(*) Independent of Patrick's implementation in Javascript (in itself based on jsqrencode.js). My version is based on Reed-Solomon for coders and is written in C. It reads the QR code generated by InDesign and can independently verify as much as possible. Test image was 34,225 pixels, not a single bit wrong.

Still, safest is to always check your QR code.


Colly, you took the long way round Actually, the first version of this script did generate a PNG, but I felt it would be easier if the script did as much "right" as possible. But if enough people feel the need, I can re-integrate the PNG code again and add a checkbox or something to write out a PNG file.

Jongware
Community Expert
JongwareCommunity ExpertAuthor
Community Expert
October 20, 2012

(Updates)

1. UTF-8 contents now has Unicode BOM added (ZXing now correctly returns the UTF-8 string, it actually din't before).

2. Only one argument required for external calling with doScript: the text string to be encoded. In that case, error correction level will be L (lowest).

3. When calling with doScript, the returned object is either null (signifying an error), or the QR code object itself. That means you can move it around, scale, or do anything else you want, like this:

obj = app.doScript(new File(app.activeScript.path+'/qrcode.jsxbin'), ScriptLanguage.JAVASCRIPT, ["hello world"]);

alert (obj);

obj.move ([0,0]);

Colin Flashman
Community Expert
Community Expert
October 20, 2012

looks like it's working to me... wow!

I don't have a smartphone to check the QR code and the iMac can't read the QR code with the inbuilt cam without Quickmark, but did find an online "decoder" to check the QR code generated.

After unembedding the QR code, I went to http://zxing.org/w/decode.jspx and submitted the qrcode.tiff which was  generated... which it didn't like. resaved the tiff as a png via photoshop and tried again... worked that time!

colly

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!