Highlighted

Match url and change in qr code

Participant ,
Oct 15, 2020

Copy link to clipboard

Copied

Hi,

I need to collect the existing QR code's URL and match partially, then need to change the QR code. Could you please guide on this?

 

Screen Shot 2020-10-15 at 2.18.40 pm.png

 

var pgItem= app.activeDocument.pageItems;
for(var g=0; g<pgItem.length; g++){
    var epsItem = pgItem[g].epss;
    if(epsItem){
       //edit QR code
       //Copy
       //match with new qr code
       //replace
    }
}

 

 

Thanks,

Selva

Adobe Community Professional
Correct answer by Sunil Yadav | Adobe Community Professional

Try this code sample:

//=======================================

editQRCode();
function editQRCode(){
    var myDoc = app.documents[0];
    for(var i = 0; i < myDoc.pages.length; i++){
        for(var p = 0; p < myDoc.pages[i].pageItems.length; p++){
            if(myDoc.pages[i].pageItems[p].epss.length > 0){
                var QRCode = getHyperlinkQRCode(myDoc.pages[i].pageItems[p].epss[0]);
                if(QRCode != null){
                    // Here you can find replace or match whatever you want to do with the link
                    QRCode = QRCode.replace("www.indesignjs.de ","www.google.com ");
                    // Here you create hyperlink QR code again, so it will be changed as well
                    myDoc.pages[i].pageItems[p].createHyperlinkQRCode(QRCode);
                    }
                }
            }
        }
    }
//=======================================
function getHyperlinkQRCode(QRCodeObject){
    try{
        var idmsFile = File (Folder.temp+"/~QR.idms");
        QRCodeObject.exportFile(ExportFormat.INDESIGN_SNIPPET, idmsFile);
        idmsFile.encoding = "UTF-8";
        idmsFile.open("r");
        var allData = new XML (idmsFile.read());
        idmsFile.close();
        idmsFile.remove();
        var qrcode = allData..HyperlinkQRCode.@UrlLink;
        if(qrcode.length() == 1) {
            return qrcode.toString();
            }
        else{
            null;
            }
        }
    catch(e){
        return null;
        }
    }
//=======================================

 

Best

Sunil

TOPICS
Scripting

Views

49

Likes

Translate

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

Match url and change in qr code

Participant ,
Oct 15, 2020

Copy link to clipboard

Copied

Hi,

I need to collect the existing QR code's URL and match partially, then need to change the QR code. Could you please guide on this?

 

Screen Shot 2020-10-15 at 2.18.40 pm.png

 

var pgItem= app.activeDocument.pageItems;
for(var g=0; g<pgItem.length; g++){
    var epsItem = pgItem[g].epss;
    if(epsItem){
       //edit QR code
       //Copy
       //match with new qr code
       //replace
    }
}

 

 

Thanks,

Selva

Adobe Community Professional
Correct answer by Sunil Yadav | Adobe Community Professional

Try this code sample:

//=======================================

editQRCode();
function editQRCode(){
    var myDoc = app.documents[0];
    for(var i = 0; i < myDoc.pages.length; i++){
        for(var p = 0; p < myDoc.pages[i].pageItems.length; p++){
            if(myDoc.pages[i].pageItems[p].epss.length > 0){
                var QRCode = getHyperlinkQRCode(myDoc.pages[i].pageItems[p].epss[0]);
                if(QRCode != null){
                    // Here you can find replace or match whatever you want to do with the link
                    QRCode = QRCode.replace("www.indesignjs.de ","www.google.com ");
                    // Here you create hyperlink QR code again, so it will be changed as well
                    myDoc.pages[i].pageItems[p].createHyperlinkQRCode(QRCode);
                    }
                }
            }
        }
    }
//=======================================
function getHyperlinkQRCode(QRCodeObject){
    try{
        var idmsFile = File (Folder.temp+"/~QR.idms");
        QRCodeObject.exportFile(ExportFormat.INDESIGN_SNIPPET, idmsFile);
        idmsFile.encoding = "UTF-8";
        idmsFile.open("r");
        var allData = new XML (idmsFile.read());
        idmsFile.close();
        idmsFile.remove();
        var qrcode = allData..HyperlinkQRCode.@UrlLink;
        if(qrcode.length() == 1) {
            return qrcode.toString();
            }
        else{
            null;
            }
        }
    catch(e){
        return null;
        }
    }
//=======================================

 

Best

Sunil

TOPICS
Scripting

Views

50

Likes

Translate

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
Oct 15, 2020 0
Adobe Community Professional ,
Oct 16, 2020

Copy link to clipboard

Copied

Try this code sample:

//=======================================

editQRCode();
function editQRCode(){
    var myDoc = app.documents[0];
    for(var i = 0; i < myDoc.pages.length; i++){
        for(var p = 0; p < myDoc.pages[i].pageItems.length; p++){
            if(myDoc.pages[i].pageItems[p].epss.length > 0){
                var QRCode = getHyperlinkQRCode(myDoc.pages[i].pageItems[p].epss[0]);
                if(QRCode != null){
                    // Here you can find replace or match whatever you want to do with the link
                    QRCode = QRCode.replace("www.indesignjs.de ","www.google.com ");
                    // Here you create hyperlink QR code again, so it will be changed as well
                    myDoc.pages[i].pageItems[p].createHyperlinkQRCode(QRCode);
                    }
                }
            }
        }
    }
//=======================================
function getHyperlinkQRCode(QRCodeObject){
    try{
        var idmsFile = File (Folder.temp+"/~QR.idms");
        QRCodeObject.exportFile(ExportFormat.INDESIGN_SNIPPET, idmsFile);
        idmsFile.encoding = "UTF-8";
        idmsFile.open("r");
        var allData = new XML (idmsFile.read());
        idmsFile.close();
        idmsFile.remove();
        var qrcode = allData..HyperlinkQRCode.@UrlLink;
        if(qrcode.length() == 1) {
            return qrcode.toString();
            }
        else{
            null;
            }
        }
    catch(e){
        return null;
        }
    }
//=======================================

 

Best

Sunil

Likes

Translate

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
Reply
Loading...
Oct 16, 2020 1
Participant ,
Oct 18, 2020

Copy link to clipboard

Copied

Hi Sunil,

This is a really nice approach to whichever we use to a different method for 'when we can't approach straight forward to the object'.

 

Thanks for the timely help.

 

 

 

Regards,

Selva

 

Likes

Translate

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
Reply
Loading...
Oct 18, 2020 0