Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

QR CODE

New Here ,
Feb 10, 2025 Feb 10, 2025

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

319
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2025 Feb 11, 2025

Copy link to clipboard

Copied

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?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2025 Feb 11, 2025

Copy link to clipboard

Copied

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.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2025 Feb 11, 2025

Copy link to clipboard

Copied

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.

demo.gifexpand image

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');

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

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.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

@Mike Witherell

 

It's also possible to add hidden labels to objects - that you can't access without knowing the "key".

 

And you can assign label not only to graphic objects - but also Tables and Cells - and few other things that are not available in the UI. 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

That sounds interesting, Robert. I did not know that.

Do you have a practical example?

When would that be useful?

Mike Witherell

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

@Mike Witherell 

 

It's just an example of where else you can use it - even with a CellStyle 🙂  

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#CellStyle.html#d1e456077__d1e458237 

 

Usefulness - for example, to save original location of the object, creation date, purpose, etc. - simply for anything - even as a note.

 

But mostly - to prevent user from modifying it. 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

I'm using it in my MagneticLayout - Liquid is unfortunately taken 😉 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

@Mike Witherell 

 

You can even use it the same as in Excel - to name a range of Cells in the Table. 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

Mike, in scripts we use .insertLabel and .extractLabel methods in cases where it is nothing to do with the user directly and is handled completely by scripts. Example usage is if I want to keep the settings that a user last used with a particular document—I can store them in a label attached to that document. They are not accessible via the GUI, so they are just for scripts. It is also cool to store a label in a DOM object with one script and then have another different script use it later on.

 

The Script Label panel is a special case because it allows a user to configure the script in some way. In the case of my QR Code script above, it would be useless if the user could not edit the labels.

- Mark

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 12, 2025 Feb 12, 2025

Copy link to clipboard

Copied

LATEST

Objects also have names - which is even handier. 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines