Copy link to clipboard
Copied
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!
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]);
...
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thank you so much! It works like a charm!
Best
Joeri
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Sorry for late response.
Can you show some screenshot of your document will make things clear.
Sunil