Skip to main content
Participant
February 11, 2025
Question

QR CODE

  • February 11, 2025
  • 4 replies
  • 662 views

"Is it possible to edit multiple QR codes simultaneously within an InDesign document?"

4 replies

Mike Witherell
Community Expert
Community Expert
February 12, 2025

Thanks for this example, Mark. 

As a teacher, I have been looking for a practical example for explaining the use of the Script Label panel.

Script Label has to be the rarest panel used in InDesign!

This demo fills the bill, nicely. Thanks very much!

Mike Witherell
m1b
Community Expert
Community Expert
February 12, 2025

I'm very glad it can help Mike. Thanks for letting me know!

 

You're right that the Script Label panel isn't used much, but it does provide a very useful place to share data between a user-defined DOM object (eg. a QR Code frame) and a script. Look for .label in the script.

- Mark

m1b
Community Expert
Community Expert
February 12, 2025

Hi @kj_28, editing the contents of QR Codes is surprisingly complicated—as Robert mentioned. However, if you are able to do a bit of work up front to label each QR Code with the contents, then it becomes a lot easier. I'm not sure if you can do that in your case, but I think it should be possible for many jobs.

 

To use the script, you must first give each QR Code a "Script Label" that looks like this:

QRCODE:https://adobe.com

QR Codes without this labelling will be ignored. Script Label can be set in the "Script Label" panel (Window > Utility > Script Label).

 

Here is a quick demo running on my computer. You only select one QR Code, and it will change all of them if they have the same label.

To set the swatch color of a QR Code (like the second one above) you must set the stroke color of its frame (and give it 0% tint if you don't want to see it). This might seem a bit strange, but I didn't want to make the script too complicated and this was a way to update multiple QRCodes which can be in arbitrary colors.

 

Look at my attached demo.indd if you're not sure how I set it up—although it's very simple. If you end up using it, let me know!

- Mark

 

Here is the script:

/**
 * Update Labelled QR Codes.js
 *
 * Based on the selected QRCode, this script will update
 * all QRCodes that have been correctly labelled with
 * the matching contents.
 *
 * Important notes:
 *
 *   1. Each QR Code (the graphic or its frame) must be labelled,
 *      via the "Script Label" panel, starting with "QRCODE:" prefix and then
 *      the text to be encoded, eg. QRCODE:https://adobe.com
 *
 *   2. To apply a swatch color to a particular QR Code, set its frame's
 *      stroke color to your desired color. If you want to hide the stroke
 *      set the tint to 0%.
 *
 * @author m1b
 * @version 2025-02-12
 * @discussion https://community.adobe.com/t5/indesign-discussions/qr-code/m-p/15144823
 */
function main() {

    var settings = {
        prefix: 'QRCODE:',
    };

    if (0 === app.documents.length)
        return alert('Please open a document and try again.');

    var doc = app.activeDocument,
        item = doc.selection[0],
        matcher = new RegExp('^' + settings.prefix + '(.+)'),
        label;

    if (!item)
        return alert('Please select a QRCode that has been labelled correctly and try again.');

    if (
        undefined != item
        && item.hasOwnProperty('label')
        && matcher.test(item.label)
    )
        label = item.label;

    else if (
        item.hasOwnProperty('graphics')
        && item.graphics.length > 0
        && matcher.test(item.graphics[0].label)
    )
        label = item.graphics[0].label;

    else if (
        item.hasOwnProperty('parent')
        && matcher.test(item.parent.label)
    )
        label = item.parent.label;

    if (!label)
        return alert('Please select a QRCode that has been labelled correctly and try again.');

    // the content to encode
    var content = label.match(matcher)[1],
        newContent = prompt('Edit QR Code:', content);

    if (!newContent)
        return;

    // check all the page items
    var items = doc.allPageItems;

    for (var i = items.length - 1; i >= 0; i--) {

        item = items[i];

        if (
            !item.label
            || !matcher.test(item.label)
        )
            continue;

        var testContent = (item.label.match(matcher) || 0)[1];

        if (testContent !== content)
            continue;

        if (item.graphics.length > 0)
            // we want the graphic, not the frame
            item = item.graphics[0];

        if (!item.isValid)
            continue;

        var parent = item.parent;
        var swatch = undefined;

        if (item.parent.strokeColor.hasOwnProperty('colorValue'))
            swatch = item.parent.strokeColor;

        // update QR Code
        item.createPlainTextQRCode(newContent, swatch);

        // update the label
        parent.label = settings.prefix + newContent;

    }

};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Update Labelled QR Codes');

 

Robert at ID-Tasker
Legend
February 12, 2025

But if user will have to set the label manually for each QR code - he can edit QR code straight away? 

 

I'm pretty sure @kj_28 wants to edit QR codes in bulk - from a list / database.

 

Or just change one word to another - like "http://" to "https://" or change name of the domain, etc.

 

m1b
Community Expert
Community Expert
February 12, 2025

Hi Robert, I am thinking of a case where you set up a document with multiple (same URL) QR Codes. Not data merge or anything. Then running script with any one selected will update all of them. I don't know if that is what OP wants—as Eugene mentioned, we don't have a lot of information yet— but I can see that being handy in some real situations.

- Mark

Robert at ID-Tasker
Legend
February 11, 2025
quote

"Is it possible to edit multiple QR codes simultaneously within an InDesign document?"


By @kj_28

 

Yes, it is. But it's not for "faint-hearted" 😉

 

It requires either re-creating the code - replacing the original one - or by modifying IDML file.

 

Community Expert
February 11, 2025

What type of edits are you looking to do? 

Can you explain your issue, what you're trying to solve and how you are achieving it at the moment?