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

Qr code web hyperlink to hyperlink for interactive pdf.

Community Beginner ,
Aug 30, 2021 Aug 30, 2021

Hello,

I'm creating a catalog in indesign. It's finished and about 800 pages. I just got asked to make it interactive. We have qr codes included on almost all the pages. I would like to ask if somebody knows if its possible to script a action to create a hyperlink from the currently used qr code web hyperlink 

What legendary scripter can help me with this 🙂

Thanks in advance!

TOPICS
Scripting
2.1K
Translate
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

correct answers 1 Correct answer

Advocate , Sep 01, 2021 Sep 01, 2021

Just Put a try catch block for exception handling, that will take of things.

//=======================================
addHyperlinkQRCode();
function addHyperlinkQRCode(){
    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++){
            try{
                if(myDoc.pages[i].pageItems[p].epss.length > 0){
                    var QRCode = getHyperlinkQRCode(myDoc.pages[i].pageItems[p].epss[0]);
       
...
Translate
Advocate ,
Aug 31, 2021 Aug 31, 2021

To add the hyperlink on QR code itself, so that while just onclick it should jump, you can give it a shot to below snippet :

//=======================================
addHyperlinkQRCode();
function addHyperlinkQRCode(){
    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){
                    myDoc.pages[i].pageItems[p].createHyperlinkQRCode(QRCode);
                    var src=myDoc.hyperlinkPageItemSources.add(myDoc.pages[i].pageItems[p]);
                    var dest = myDoc.hyperlinkURLDestinations.add(QRCode);
                    myDoc.hyperlinks.add(src, dest);
                    }
                }
            }
        }
    }
//=======================================
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

Translate
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 Beginner ,
Sep 01, 2021 Sep 01, 2021

Hi Sunil!

Thanks for the snippet, but unfortunately it is not working. I'm getting an error.
See the attachment for the window error.

I hope this doesn't take to much time to find a fix for this!
Thanks alot for the effort!

Best 
Joeri

Translate
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
Advocate ,
Sep 01, 2021 Sep 01, 2021

Just Put a try catch block for exception handling, that will take of things.

//=======================================
addHyperlinkQRCode();
function addHyperlinkQRCode(){
    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++){
            try{
                if(myDoc.pages[i].pageItems[p].epss.length > 0){
                    var QRCode = getHyperlinkQRCode(myDoc.pages[i].pageItems[p].epss[0]);
                    if(QRCode != null){
                        myDoc.pages[i].pageItems[p].createHyperlinkQRCode(QRCode);
                        var src=myDoc.hyperlinkPageItemSources.add(myDoc.pages[i].pageItems[p]);
                        var dest = myDoc.hyperlinkURLDestinations.add(QRCode);
                        myDoc.hyperlinks.add(src, dest);
                        }
                    }
                }
            catch(e){}
            }
        }
    }
//=======================================
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

Translate
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 Beginner ,
Sep 01, 2021 Sep 01, 2021

Thank you so much! It works like a charm!

Best
Joeri

Translate
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
New Here ,
Jul 14, 2022 Jul 14, 2022

Thanks for the script. For QR-codes outside of test boxes it works fine. But when the QR-code stands inside an text field or an anchor object it doesn't work. Is there a solution for this? Thank you for your efforts. 

 

Best 

Julian

Translate
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 ,
Jul 14, 2022 Jul 14, 2022

 

Changed pageItems to allPageItems per page. Didn't test; let me know if errors.

//=======================================
addHyperlinkQRCode();
function addHyperlinkQRCode(){
    var myDoc = app.documents[0];
    var apis;
    for(var i = 0; i < myDoc.pages.length; i++){
        apis = myDoc.pages[i].allPageItems;
        for(var p = 0; p < apis.length; p++){
            try{
                if(apis[p].epss.length > 0){
                    var QRCode = getHyperlinkQRCode(apis[p].epss[0]);
                    if(QRCode != null){
                        apis[p].createHyperlinkQRCode(QRCode);
                        var src=myDoc.hyperlinkPageItemSources.add(apis[p]);
                        var dest = myDoc.hyperlinkURLDestinations.add(QRCode);
                        myDoc.hyperlinks.add(src, dest);
                        }
                    }
                }
            catch(e){}
            }
        }
    }
//=======================================
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;
        }
    }

 

Translate
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
New Here ,
Jul 14, 2022 Jul 14, 2022

Tested it, but it works like the script before. Outside of textboxes it works fine, but in textboxes it won't work. Is there any other option? Thank you very much for your help.

 

Best

Julian

Translate
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
Advocate ,
Dec 04, 2022 Dec 04, 2022

Sorry for late response.

Can you show some screenshot of your document will make things clear.

 

Sunil

Translate
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
New Here ,
Jun 06, 2025 Jun 06, 2025
LATEST

Thank you @Sunil Yadav, it works perfectly!

Translate
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