How to find and edit QR Codes using scripting
Copy link to clipboard
Copied
There appears to be several methods available in order to create QR Codes within the Scripting API. What we need is a way to find each QR Code and examine/edit the URL. There apprears to be nothing listed for this within the API documentation. Is there any way to step through the Graphics in each doucment, determine whether or not they are QR Codes, and if they are, to then check/edit the URL?
Copy link to clipboard
Copied
Hi @James Gifford—NitroPress I'm no expert on this, but I'm confident enough to answer your two questions
> ... whether ID stores that (text or equivalent) data somewhere, as a separate, theoretically editable element, independently of the little dotty graphic.
It definitely does store it somewhere "alongside" the QR code graphic. We know that because of the snippet trick. However we don't know where. It could be, for example, an "inserted label" of the graphic or frame (aside: I wish we could get a list of all of an objects labels to extract!) or, more likely, simply an internal property that we have no access to aside from the snippet trick. The fact that the contents are exposed when exporting a snippet is surprising to me—I mean why not just export the graphic alone? The fact that it re-generates, as Robert noticed, is even more surprising.
> does it simply "read" the code to produce the re-editing data/string?
No it doesn't read the QR Code graphic at all. Therefore this workaround only works with Indesign-generated QR codes. I looked into the feasibility of decoding a graphic QR code via script but it was too involved.
For now it seems that OP's workaround is pretty much the best we can do, unless I'm missing something.
- Mark
Copy link to clipboard
Copied
Not sure why are you surprised?
Snippet is the same as IDML.
How else InDesign can re-generate QR code - if there would be no original info available?
The whole process can be easily automated.
Copy link to clipboard
Copied
@Robert at ID-Tasker Oh yes, it would have to exist in the IDML. I hadn't thought of that. Makes sense. Thanks.
Copy link to clipboard
Copied
I did try to be a bit sneaky, parsed the graphic object, then wrote all the data fields to a JSON file to see if I could find any "hidden" data. But unfortunately, I didn't see anything new. Again... it really boggles my mind that Adobe would do things this way. You can see the URL just by hovering your mouse over the QR Code... So you KNOW the data is there somewhere! Fer cry'n out loud, just let us open and edit it in scripting just as you would with the "Edit QR Code" dialog. Is it really too much to ask?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
True... but that's like saying, "Never drive anywhere, and you'll never get into an accident"
Copy link to clipboard
Copied
True... but that's like saying, "Never drive anywhere, and you'll never get into an accident"
By Ken Webster
Yes, less money that needs to be spent on testing 😉
Copy link to clipboard
Copied
I haven't checked what is in the "linked" file that represents QR code - that is stored in the temp folder - I'll do it tomorrow.
Copy link to clipboard
Copied
> I haven't checked what is in the "linked" file that represents QR code - that is stored in the temp folder
By the way, on my system here, that temp file doesn't even exist! Let me know what you discover.
- Mark
Copy link to clipboard
Copied
I haven't checked what is in the "linked" file that represents QR code - that is stored in the temp folder - I'll do it tomorrow.
By Robert at ID-Tasker
I've already checked... There IS NO FILE!! Apparently, it's just a dummy entry that InDesign makes to establish the fact the the graphic is infact a QR Code. The three criteria I use to determin if it's a QR Code are...
1: Use a RegExp to parse the *fake* Path: /\/var\/folders\/.*\/QR Code.*/ Note: This is for Mac, but I'm sure Windows is similar
2: The Graphic is EPS
3: The Graphic is embedded.
Copy link to clipboard
Copied
So... the data is in there, wholly separate from the (EPS) graphic... but no one knows where, or can find it at the file-data level.
Yikes.
Copy link to clipboard
Copied
So... the data is in there, wholly separate from the (EPS) graphic... but no one knows where, or can find it at the file-data level.
Yikes.
By James Gifford—NitroPress
After you export as a Snippet - it's kind of at file level 😉
Then you can modify it, re-import and update.
Copy link to clipboard
Copied
Actually - You can't really 'modify' an existing QR Code (that I know of). I think your only solution in that situation is just to delete the existing QRC and create a new one. Unless of course, you need some/part of the previous URL, then you'll just have to do the XML dance. But even then, you'll still have to delete the original QRC and create a new one.... correct??
Copy link to clipboard
Copied
I was always referring to the Snippet - you export Snippet, edit it, delete original QR code graphic object, place edited Snippet, refresh preview.
Copy link to clipboard
Copied
@m1b said: "I've created a feature request for this".
Hi Mark,
I voted.
ExtendScript
Currently we have several methods of creating QR codes.
The universal one is:
createPlainTextQRCode()
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Graphic.html#d1e258171__d1e260352
Others that are listed are:
createEmailQRCode()
createHyperlinkQRCode()
createTextMsgQRCode()
createVCardQRCode()
So I would suggest the following new methods:
readPlainTextQRCode()
( from existing QRCode )
writePlainTextQRCode()
( to existing QRCode )
Maybe also pairs of read/write methods for the Email, Hyperlink, TextMsg and VCard kinds.
But basically we are good with PlainText, because every of the four kinds of QR codes listed additionally can be done with PlainText.
For all who like to vote:
[Scripting] Edit QR Code
It would be good if we could read the contents of an Indesign-generated QR Code via script.
@m1b, January 22, 2025 ·
https://indesign.uservoice.com/forums/601021-adobe-indesign-feature-requests/suggestions/49362638--s...
Thanks,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Thanks Uwe, something like what you suggest would work well.
Copy link to clipboard
Copied
@m1b said: "… something like what you suggest would work well."
Hi Mark,
not to forget changing other properties should also be possible like:
Fill Color of QR code itself.
Width of margins from the QR code's square to the edge of the EPS graphic.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
It's really not rocket science... Just a bit silly (IMHO) that we need to do all these steps just to find the URL of a QR Code.
You just step through your Graphic Items until you find a QR Code. You then write the PageItem to an XML file like this, and then read it back in and parse what you need.
grafArry[index].exportFile( ExportFormat.INDESIGN_SNIPPET, qrFile );
qrFile.open("r");
theXMLData = new XML( qrFile.read() );
qrFile.close();
// Don't know if QR Code is Plain Text or Web Hyperlink, so check for both
if(theXMLData)
{
// Obtain the URL from the XML data
theQRLink = theXMLData..HyperlinkQRCode.@UrlLink;
theQRLinkTxt = theXMLData..PlainTextQRCode.@PlainText;
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Good find @Robert at ID-Tasker! I'm pleasantly surprised that works. 🙂
Copy link to clipboard
Copied
hi
looking in the properties of the links in an Indesign document
I've seen then QRCodes generated in Indesign have
the name starting with "QR Codexxxxx" and the status link embedded
so you can make an array of all links and test name and status to find every QR Code
Copy link to clipboard
Copied
Yes, we know that - here is my screenshot:
Copy link to clipboard
Copied
Actually... I use three criteria to check that I posted here...
https://community.adobe.com/t5/indesign-discussions/how-to-find-and-edit-qr-codes-using-scripting/m-...
... but yours should work. Untill Adobe gives us a rock solid way to read the data and know 100% for sure that it is indeed a QR Code, I'm taking the cautious, paranoid route.


-
- 1
- 2