Skip to main content
dapleh
New Participant
September 20, 2017
Answered

get Text from QRCode

  • September 20, 2017
  • 1 reply
  • 1084 views

InDesign allows me to place a QRCode made from simple text in the document. Menu: Object / generate QRCode using Indesign 2017.1

Is there a way to read the content from the generated object?  I can find the object on the layer but not the underlying text. When hovering with the mouse on the qrCode, the text is shown.

Was already going through the object tree with ExtendScript-Toolkit, not successful though..

Thanks in advance,

Daniel

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi,

A possible approach given that you properly reached the text based QR ode:

//Take care of having a valid reference to the QRCode

//Actually it's a EPS file with some embedded link property

var qRCode = app.selection[0];

//We do export a snippet

var tempFile = File ( Folder.temp+"/qr.idms" );

qRCode.exportFile ( ExportFormat.INDESIGN_SNIPPET , tempFile);

//Snippets are xml files

//And the inner QRCode text is clearly exposed

//So what we need is to load the XML string from file

//and turn it into a regular javascript object

tempFile.encoding = "UTF-8";

tempFile.open("r");

var xObj = XML ( tempFile.read() );

tempFile.close();

tempFile.remove();

//Once that done, it's easy to go and pick the PlainText attribute which hosts the text content

var txt = xObj..@PlainText;

//Finally

if ( txt.length() ) {

alert( txt[0] );

}

else {

alert("No text found sorry" );

}

1 reply

Loic.Aigon
Loic.AigonCorrect answer
Brainiac
September 21, 2017

Hi,

A possible approach given that you properly reached the text based QR ode:

//Take care of having a valid reference to the QRCode

//Actually it's a EPS file with some embedded link property

var qRCode = app.selection[0];

//We do export a snippet

var tempFile = File ( Folder.temp+"/qr.idms" );

qRCode.exportFile ( ExportFormat.INDESIGN_SNIPPET , tempFile);

//Snippets are xml files

//And the inner QRCode text is clearly exposed

//So what we need is to load the XML string from file

//and turn it into a regular javascript object

tempFile.encoding = "UTF-8";

tempFile.open("r");

var xObj = XML ( tempFile.read() );

tempFile.close();

tempFile.remove();

//Once that done, it's easy to go and pick the PlainText attribute which hosts the text content

var txt = xObj..@PlainText;

//Finally

if ( txt.length() ) {

alert( txt[0] );

}

else {

alert("No text found sorry" );

}

dapleh
daplehAuthor
New Participant
September 25, 2017

Thanks a lot,

works very good and saved me a lot of time...

Have a nice day!

Daniel

Loic.Aigon
Brainiac
September 25, 2017

Glad it helped.