-
1. Re: Script for converting hyperlinks to buttons?
Kasyan Servetsky Feb 1, 2014 8:29 AM (in response to Petteri_Paananen)Are you a scripter?
I made such a script but it was intended for a specific workflow and can't be used as it is. You'll have to rework it to your needs or, at least, can use it as a starting point.
If you're interested, I'll post it.
Kas
-
2. Re: Script for converting hyperlinks to buttons?
Petteri_Paananen Feb 1, 2014 9:20 AM (in response to Kasyan Servetsky)Hi
I´m not scripter but I have edited scripts so I could give it a change if you were so kind to send that script to me....=) And I have associates who are more experienced than I am, so I can even ask help....
Thanks a lot!
-
3. Re: Script for converting hyperlinks to buttons?
Kasyan Servetsky Feb 1, 2014 10:27 AM (in response to Petteri_Paananen)Here it is:
/* Copyright 2012, Kasyan Servetsky November 29, 2012 Written by Kasyan Servetsky http://www.kasyan.ho.com.ua e-mail: askoldich@yahoo.com */ //====================================================================================== var scriptName = "Convert hyperlinks to buttons - 1.0"; Main(); //===================================== FUNCTIONS ====================================== function Main() { var hyperlink, source, sourceText, destination, page, arr, outlinedText, gb, button, behavior, barodeCount = 0, hypCount = 0; if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true); var startTime = new Date(); var doc = app.activeDocument; var layer = doc.layers.item("Buttons"); var swatch = doc.swatches.item("RGB Yellow"); var hyperlinks = doc.hyperlinks; var progressWin = new Window ("window", scriptName); progressBar = progressWin.add ("progressbar", undefined, 0, undefined); progressBar.preferredSize.width = 450; progressTxt = progressWin.add("statictext", undefined, "Starting processing hyperlinks"); progressTxt.preferredSize.width = 400; progressTxt.preferredSize.height = 30; progressTxt.alignment = "left"; progressBar.maxvalue = hyperlinks.length; progressWin.show(); for (var i = hyperlinks.length-1; i >= 0; i--) { hyperlink = hyperlinks[i]; source = hyperlink.source; sourceText = source.sourceText; destination = hyperlink.destination; page = sourceText.parentTextFrames[0].parentPage; barodeCount++; progressBar.value = barodeCount; progressTxt.text = "Processing hyperlink " + hyperlink.name + " (Page - " + page.name + ")"; arr = sourceText.createOutlines(false); outlinedText = arr[0]; gb = outlinedText.geometricBounds; outlinedText.remove(); button = page.buttons.add(layer, {geometricBounds: gb, name: hyperlink.name}); button.fillColor = swatch; button.fillTint = 50; button.groups[0].transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; behavior = button.gotoURLBehaviors.add(); behavior.url = destination.destinationURL; hyperlink.remove(); source.remove(); hypCount++; } var endTime = new Date(); var duration = GetDuration(startTime, endTime); progressWin.close(); alert("Finished. " + hypCount + " hyperlinks were convertted to buttons.\n(time elapsed: " + duration + ")", scriptName); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function GetDuration(startTime, endTime) { var str; var duration = (endTime - startTime)/1000; duration = Math.round(duration); if (duration >= 60) { var minutes = Math.floor(duration/60); var seconds = duration - (minutes * 60); str = minutes + ((minutes != 1) ? " minutes, " : " minute, ") + seconds + ((seconds != 1) ? " seconds" : " second"); if (minutes >= 60) { var hours = Math.floor(minutes/60); minutes = minutes - (hours * 60); str = hours + ((hours != 1) ? " hours, " : " hour, ") + minutes + ((minutes != 1) ? " minutes, " : " minute, ") + seconds + ((seconds != 1) ? " seconds" : " second"); } } else { str = duration + ((duration != 1) ? " seconds" : " second"); } return str; } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ErrorExit(error, icon) { alert(error, scriptName, icon); exit(); } -
4. Re: Script for converting hyperlinks to buttons?
Petteri_Paananen Feb 2, 2014 12:00 PM (in response to Kasyan Servetsky)Thanks a lot, this works just fine... I changed the RGB Yellow to None and button name to be simply link... then it works for my purpose...
I probaply remove requirement for layer named Buttons too... or at least I add there few lines which generate that required layer on the fly...
Petteri
-
5. Re: Script for converting hyperlinks to buttons?
Petteri_Paananen Feb 2, 2014 12:20 PM (in response to Petteri_Paananen)One more question.. sorry...=)
I ran some tests and noticed that only text hyperlinks are supported... do you have any tip how it could be possible to get image/graphic hyperlinks supported as well.. if it´s easy enough I could try to do it myself....
Petteri
-
6. Re: Script for converting hyperlinks to buttons?
Kasyan Servetsky Feb 3, 2014 9:35 AM (in response to Petteri_Paananen)Hi Petteri,
Here's quick & dirty solution (totally untested). I assume that images are simply placed in their containers (e.g. a rectangle, oval, etc. — not in a group or nested).
Here I posted a sample document so you could test the script against it.
Currently the script works with two types of hyperlinks: which have either HyperlinkTextSource or HyperlinkPageItemSource as source. But if necessary, other types can be easily added.
/* Copyright 2014, Kasyan Servetsky February 3, 2014 Written by Kasyan Servetsky http://www.kasyan.ho.com.ua e-mail: askoldich@yahoo.com */ //====================================================================================== var scriptName = "Convert hyperlinks to buttons - 2.0", doc; Main(); //===================================== FUNCTIONS ====================================== function Main() { var hyperlink, source, sourceText, destination, page, arr, outlinedText, gb, button, behavior, sourcePageItem, barodeCount = 0, hypCount = 0; if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true); var startTime = new Date(); doc = app.activeDocument; var layer = MakeLayer("Buttons"); var swatch = MakeColor("RGB Yellow", ColorSpace.RGB, ColorModel.process, [255, 255, 0]); var hyperlinks = doc.hyperlinks; var progressWin = new Window ("window", scriptName); progressBar = progressWin.add ("progressbar", undefined, 0, undefined); progressBar.preferredSize.width = 450; progressTxt = progressWin.add("statictext", undefined, "Starting processing hyperlinks"); progressTxt.preferredSize.width = 400; progressTxt.preferredSize.height = 30; progressTxt.alignment = "left"; progressBar.maxvalue = hyperlinks.length; progressWin.show(); for (var i = hyperlinks.length-1; i >= 0; i--) { hyperlink = hyperlinks[i]; source = hyperlink.source; destination = hyperlink.destination; if (source.constructor.name == "HyperlinkTextSource") { sourceText = source.sourceText; page = sourceText.parentTextFrames[0].parentPage; arr = sourceText.createOutlines(false); outlinedText = arr[0]; gb = outlinedText.geometricBounds; outlinedText.remove(); } else if (source.constructor.name == "HyperlinkPageItemSource") { sourcePageItem = source.sourcePageItem; gb = sourcePageItem.geometricBounds; page = sourcePageItem.parentPage; } barodeCount++; progressBar.value = barodeCount; progressTxt.text = "Processing hyperlink " + hyperlink.name + " (Page - " + page.name + ")"; if (source.constructor.name == "HyperlinkTextSource" || source.constructor.name == "HyperlinkPageItemSource") { button = page.buttons.add(layer, {geometricBounds: gb, name: hyperlink.name}); button.fillColor = swatch; button.fillTint = 50; button.groups[0].transparencySettings.blendingSettings.blendMode = BlendMode.MULTIPLY; behavior = button.gotoURLBehaviors.add(); behavior.url = destination.destinationURL; hyperlink.remove(); source.remove(); hypCount++; } } var endTime = new Date(); var duration = GetDuration(startTime, endTime); progressWin.close(); alert("Finished. " + hypCount + " hyperlinks were convertted to buttons.\n(time elapsed: " + duration + ")", scriptName); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function GetDuration(startTime, endTime) { var str; var duration = (endTime - startTime)/1000; duration = Math.round(duration); if (duration >= 60) { var minutes = Math.floor(duration/60); var seconds = duration - (minutes * 60); str = minutes + ((minutes != 1) ? " minutes, " : " minute, ") + seconds + ((seconds != 1) ? " seconds" : " second"); if (minutes >= 60) { var hours = Math.floor(minutes/60); minutes = minutes - (hours * 60); str = hours + ((hours != 1) ? " hours, " : " hour, ") + minutes + ((minutes != 1) ? " minutes, " : " minute, ") + seconds + ((seconds != 1) ? " seconds" : " second"); } } else { str = duration + ((duration != 1) ? " seconds" : " second"); } return str; } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function MakeLayer(name, layerColor) { var layer = doc.layers.item(name); if (!layer.isValid) { layer = doc.layers.add({name: name}); if (layerColor != undefined) layer.layerColor = layerColor; } return layer; } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function MakeColor(colorName, colorSpace, colorModel, colorValue) { var doc = app.activeDocument; var color = doc.colors.item(colorName); if (!color.isValid) { color = doc.colors.add({name: colorName, space: colorSpace, model: colorModel, colorValue: colorValue}); } return color; } //-------------------------------------------------------------------------------------------------------------------------------------------------------- function ErrorExit(error, icon) { alert(error, scriptName, icon); exit(); } //-------------------------------------------------------------------------------------------------------------------------------------------------------- -
7. Re: Script for converting hyperlinks to buttons?
Petteri_Paananen Feb 3, 2014 11:03 AM (in response to Kasyan Servetsky)Hei this is absolutely GREAT! Thank you million times Kasyan...=)
Petteri
-
8. Re: Script for converting hyperlinks to buttons?
Arvindkmar Feb 4, 2014 11:10 PM (in response to Kasyan Servetsky)Hi Kasyan,
Thank you very much for your reply. I am not a scriptor. I am just a layout operator in Indesign. I have tested both the scripts provided by you, they are working but unfortunately I cannot use it.
I want to request you if you could help me. I have a URL Character style in my book, according to your script "Make hyperlinks from URLs - 1.0" made on "September 12, 2013" it is find all the URL but the script is changing the original text of the book and replacing with the domain name.
I just want the script to find the URL style and convert it to Hyperlink.
For example this is the actual URL in the book:
https://developer.atlassian.com/display/DOCS/ConfigureIDEAtousethe+SDK
ORIGINAL text changed to when I run the script:
developer.atlassian.com
When I run the script the original text in the book is changed to the Domain name, and also Hyperlink is created for the full original text in PDF.
Its appreciated that you take the initiative and reply to our queries.
-
9. Re: Script for converting hyperlinks to buttons?
patrickbcm Feb 5, 2014 1:53 PM (in response to Arvindkmar)Hello,
I have another question. I make Apps with adobe DPS and when i have a open Indesign document it will work, but sometime i get a magazine as PDF.
I import the pdf in Indesign CS5 Mac.
Is it also possible to fix this script for pdf document?
Kind regards,
Patrick
-
10. Re: Script for converting hyperlinks to buttons?
Petteri_Paananen Feb 12, 2014 8:57 AM (in response to patrickbcm)This is interesting.
I have to deal with placed PDFs as well. As far as I know, InDesign treats placed PDFs a bit like images so I would be greatly suprised if it turned out to be possible to read hyperlink data from them and re-generate native InDesign hyperlinks or buttons based on that information.
I really hope I´m wrong tough...

