22 Replies Latest reply on May 3, 2014 12:07 AM by sanjascreenname

    [Ann] QR Code for InDesign CS4 and up

    [Jongware] Most Valuable Participant

      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.




      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.

        • 1. Re: [Ann] QR Code for InDesign CS4 and up
          Colin Flashman Adobe Community Professional

          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!



          • 2. Re: [Ann] QR Code for InDesign CS4 and up
            [Jongware] Most Valuable Participant



            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]);
            • 3. Re: [Ann] QR Code for InDesign CS4 and up
              [Jongware] Most Valuable Participant


              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.

              • 4. Re: [Ann] QR Code for InDesign CS4 and up

                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


                             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,


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


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






                here is a MECARD template for you:







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



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

                • 5. Re: [Ann] QR Code for InDesign CS4 and up
                  Colin Flashman Adobe Community Professional

                  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.



                  • 6. Re: [Ann] QR Code for InDesign CS4 and up
                    [Jongware] Most Valuable Participant

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

                    • 7. Re: [Ann] QR Code for InDesign CS4 and up
                      Colin Flashman Adobe Community Professional

                      OIC. Must admit to not owning a smartphone and being unaware of the MECARD detail


                      I felt that sergemca's script had more potential than files assembled out of data merge, and could be used for any document where particular placeholders were set up, regardless of how the document was created. For example, a parts catalogue that has URLs for each product, whether created from scratch; as a result of data merge or XML; could benefit from this script by employing a method similar to my last post.


                      In terms of data merge, if it is used off-of-the-shelf, it can't auto-generate text frames of its own based on the incoming data. I've been able to get data merge to do some weird and wonderful things as outlined on my blog, but the possibilities with scripting and data merge are yet to fully be explored. Loic Aigon is a pioneer with this, he has several scripts that push the envelope and do things outside the normal scope of data merge, but apart from what he's done, i'm not sure of its further potential.

                      • 8. Re: [Ann] QR Code for InDesign CS4 and up

                        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.

                        • 9. Re: [Ann] QR Code for InDesign CS4 and up

                          This is an awesome script, but I have 3 questions and any help would be appreciated. I've been trying to reverse engineer different scripts to duct tape what I want together, but no luck. So here goes:


                          How would I go about resizing the actual QRCODE to 56px x 19mm?

                          How would I reposition this from an area other than the center like 256px x 114mm?

                          How could I recolor it with a swatch in my pallete?



                          Any help would be deeply appreciated,


                          • 10. Re: [Ann] QR Code for InDesign CS4 and up
                            [Jongware] Most Valuable Participant

                            Jimalya, as I mention in the first post, you don't have to tinker with the original script. Just have your own script draw a target rectangle any way you want, and then pass this rectangle to my script. It returns the created QR code, so you can then give it any color you want -- below, I set the color for rectangle.images[0], so the color of the QR code itself is changed. If you want to change the background color, apply this to rectangle.fillColor instead.


                            The units in this example script are "unspecified"; that is, they automatically use your current horizontal and vertical units. (By the way, don't you think 19 x 19 mm is a bit small for a QR code?)


                            // add a plain default rectangle
                            myRect = app.activeDocument.rectangles.add ();
                            // some constants
                            cxpos = 256;
                            cypos = 114;
                            width = 56;
                            height = 19;
                            // set the center, width and height
                            myRect.geometricBounds = [ cypos-height/2, cxpos-width/2, cypos+height/2, cxpos+width/2 ];
                            // Fill Me In. The '1' in the argument array is the Error Correction Level
                            obj = app.doScript(new File(app.activeScript.path+'/qrcode.jsxbin'), ScriptLanguage.JAVASCRIPT, ["hello", 1, myRect] );
                            // .. now you can change the color of the image ..
                            obj.images[0].fillColor = app.activeDocument.swatches.item("Red");


                            The first step in the acquisition of wisdom is silence, the second is listening, the third memory, the fourth practice -- and the fifth is teaching others.

                            • 11. Re: [Ann] QR Code for InDesign CS4 and up
                              Jimalya7 Level 1

                              Thank you so much for your reply Jongware. I appreciate your help. Yeah, I agree that 19mm is small, but I was using the info panel in Indesign and it had pixels for the width and mm for the height and couldn't quite figure out a way to have the info be all in pixels.


                              I'll work with example you provided me and see where it gets me.


                              Thanks Again!

                              • 12. Re: [Ann] QR Code for InDesign CS4 and up
                                Jimalya7 Level 1

                                Thank you Jongware, your example was a great teaching tool.


                                I was able to implement this using the MECARD example provided from sergemca, but when trying to do it with VCARD, it doesn't work. The scan works when it is produced directly from the QRCODE.jsx script and input directly into the JONGWARE QRCODE GENERATOR, but not with the customized version reading the data from the textframe. The QRCODE is created, but when scanned, it just brings up the contact area in my phone, but no data. Note: I did update the script to look for BEGIN:VCARD, which is the same as what I input directly. The QRCODE appears, but doesn't bring in any data when scanned.


                                Any ideas why this would work differently when entered directly or from a textframe?


                                Here is the VCARD code I'm using:





                                FN:Jimalya Smith

                                TITLE:Some Title

                                ORG:Some Place





                                • 13. Re: [Ann] QR Code for InDesign CS4 and up
                                  [Jongware] Most Valuable Participant

                                  Any ideas why this would work differently when entered directly or from a textframe?


                                  I don't have any experience with uses of QR codes other than (simple) URLs. But in your case, you could check what happens to the hard returns at the end of each line. All the rest is plain text and should not be a problem.

                                  • 14. Re: [Ann] QR Code for InDesign CS4 and up
                                    Jimalya7 Level 1

                                    Thank you so much for your help! I'll keep researching.


                                    Matt Pleasant

                                    • 15. Re: [Ann] QR Code for InDesign CS4 and up
                                      Laubender Adobe Community Professional & MVP

                                      @Jongware – just to complement the topic of generating QR codes in InDesign, see the following sneak peek of InDesign CS(next*) by John Nack:






                                      *we will have to wait a bit longer to know how it will be named exactly… My guess is: "CS7".

                                      • 16. Re: [Ann] QR Code for InDesign CS4 and up
                                        [Jongware] Most Valuable Participant

                                        It only took me a few evenings to write that script, so I guess Adobe had some time left after adding a few *really* necessary improvements :-P

                                        • 17. Re: [Ann] QR Code for InDesign CS4 and up
                                          Laubender Adobe Community Professional & MVP

                                          Oh boy!
                                          Creating QR codes in InDesign seems to be a top priority feature ;-)
                                          Last-In-First-Out principle?



                                          • 18. Re: [Ann] QR Code for InDesign CS4 and up
                                            [Jongware] Most Valuable Participant

                                            Call me back when this is implemented: "New In CS7! You can now also search text BACKWARDS!"

                                            • 19. Re: [Ann] QR Code for InDesign CS4 and up
                                              Pickory Level 3

                                              Imitation is the sincerest of flattery.

                                              • 20. Re: [Ann] QR Code for InDesign CS4 and up
                                                Ampersand et

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



                                                • 21. Re: [Ann] QR Code for InDesign CS4 and up
                                                  ThinkingThings Level 1



                                                  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,



                                                  • 22. Re: [Ann] QR Code for InDesign CS4 and up

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