Skip to main content
Inspiring
February 4, 2021
Answered

Script qr code

  • February 4, 2021
  • 1 reply
  • 1930 views

Can somebody help me with a script that find url codes and change it to a QR code with a object style named test.

 

kind regards,

Patrick

This topic has been closed for replies.
Correct answer Sunil Yadav

Try this snippet : 

 

//////////////////////////////////////////////////////////////////////////////////////////////////////
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+ \\/.\\w_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length ; i){
    var urlLink = allFound[i].texts[0].contents.toString();
    var qrCodeObject = allFound[i].insertionPoints[-1].rectangles.add({geometricBounds:[0, 0, 10, 10]});
    qrCodeObject.createHyperlinkQRCode(urlLink);
    qrCodeObject.label = "QR-URL";
    allFound[i].texts[0].contents = "";
    app.documents[0].recompose();
    allFound = app.documents[0].findGrep();
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////

 

[Code Edited]

Sunil

1 reply

Sunil Yadav
Braniac
February 9, 2021

Try this below snippet for add QR code for URL:

//////////////////////////////////////////////////////////////////////////////////////////////////////
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "(ftp:\/\/|www\.|https?:\/\/){1}[a-zA-Z0-9u00a1-\uffff0-]{2,}\.[a-zA-Z0-9u00a1-\uffff0-]{2,}(\S*)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length; i){
    var urlLink = allFound[0].texts[0].contents.toString();
    var qrCodeObject = allFound[i].insertionPoints[-1].rectangles.add({geometricBounds:[0, 0, 10, 10]});
    qrCodeObject.createHyperlinkQRCode(urlLink);
    qrCodeObject.label = "QR-URL";
    allFound[0].texts[0].contents = "";
    app.documents[0].recompose();
    allFound = app.documents[0].findGrep();
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////

 

After placement of all QR code if you want to change size of those QR codes find them with their script label & can change the geometric bounds or apply any object style.

 

Best

Sunil

Inspiring
February 11, 2021

When i have a URL like www.bcm.nl it's working fine. When i have http://www.bcm.nl he makes a QR code of http://www.bcm and the .nl he dont take it.

so i get (QR code).nl

Sunil Yadav
Sunil YadavCorrect answer
Braniac
February 12, 2021

Try this snippet : 

 

//////////////////////////////////////////////////////////////////////////////////////////////////////
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = "((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+ \\/.\\w_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)";
var allFound = app.documents[0].findGrep();
for(var i = 0; i < allFound.length ; i){
    var urlLink = allFound[i].texts[0].contents.toString();
    var qrCodeObject = allFound[i].insertionPoints[-1].rectangles.add({geometricBounds:[0, 0, 10, 10]});
    qrCodeObject.createHyperlinkQRCode(urlLink);
    qrCodeObject.label = "QR-URL";
    allFound[i].texts[0].contents = "";
    app.documents[0].recompose();
    allFound = app.documents[0].findGrep();
    }
//////////////////////////////////////////////////////////////////////////////////////////////////////

 

[Code Edited]

Sunil