A script to make all page references into hyperlinks

Hi,
I have a customer request to make all pages references into hyperlinks.
For example: when you see in the text of the PDF "page 4", you can click on it and move to page 4. This of course can be done manually with InDesign. The problem starts when you have whole load of them. In addition to that, I have this project as a book, with several different documents...
I used the script "Automatic hyperlink of each word in a file" from http://www.nobrainer.dk/automatic-hyperlink-of-each-word-in-a-file/ as a base, and modified it for my porpuse. Currently it still produces errors. Any idea what's the bug?
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var myHyperlinkStyle = myDocument.characterStyles.item("hyperlink"); // replace hyperlink with name of your char style for links
//alert(myHyperlinkStyle);
main();
} else {
alert("Please open a document");
function main() {
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//the value to find
myFindVal = "page (\\d+)";
doSearchAndReplace(myFindVal, app.activeDocument);
// reset search
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
function doSearchAndReplace(stringfind, searchin) {
app.findGrepPreferences.findWhat = stringfind;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
var myFoundItems = searchin.findGrep();
for (i = 0; i < myFoundItems.length; i++) {
var item = myFoundItems[i].contents;
//the destination page
var destPage = item.slice(5);
var myHyperlinkDestination = myMakeHyperlinkDestination(destPage);
myMakeHyperlink(myFoundItems[i], myHyperlinkDestination);
myFoundItems[i].applyCharacterStyle(myHyperlinkStyle, false);
function myMakeHyperlink(myFoundItem, myHyperlinkDestination){
try {
var myHyperlinkTextSource = myDocument.hyperlinkTextSources.add(myFoundItem);
var myHyperlink = myDocument.hyperlinks.add(myHyperlinkTextSource, myHyperlinkDestination);
myHyperlink.visible = false;
catch(myError){
function myMakeHyperlinkDestination(myDestPage){
//If the hyperlink destination already exists, use it;
//if it doesn't, then create it.
try{
var myHyperlinkDestination = myDocument.hyperlinkDestinations.item(myDestPage);
myHyperlinkDestination.name;
catch(myError){
myHyperlinkDestination = myDocument.hyperlinkPageDestinations.add(myDestPage);
myHyperlinkDestination.destinationPage = myDestPage;
myHyperlinkDestination.name = myDestPage;
//Set other hyperlink properties here, if necessary.
return myHyperlinkDestination;

well, after some more digging into it, I found the bugs and corrected, here is the corrected version (now I only need to figure out how to do it on an entire book...):
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
var myHyperlinkStyle = myDocument.characterStyles.item("hyperlink"); // replace hyperlink with name of your char style for links
//alert(myHyperlinkStyle);
main();
} else {
alert("Please open a document");
function main() {
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
//the value to find
myFindVal = "page (\\d+)";
doSearchAndReplace(myFindVal, app.activeDocument);
// reset search
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences = NothingEnum.nothing;
function doSearchAndReplace(stringfind, searchin) {
app.findGrepPreferences.findWhat = stringfind;
//Set the find options.
app.findChangeGrepOptions.includeFootnotes = true;
app.findChangeGrepOptions.includeHiddenLayers = false;
app.findChangeGrepOptions.includeLockedLayersForFind = false;
app.findChangeGrepOptions.includeLockedStoriesForFind = false;
app.findChangeGrepOptions.includeMasterPages = false;
var myFoundItems = searchin.findGrep();
for (i = 0; i < myFoundItems.length; i++) {
var item = myFoundItems[i].contents;
//the destination page
var destPageNumber = item.slice(5);
var destPage = searchin.pages.itemByName(destPageNumber);
var myHyperlinkDestination = myMakeHyperlinkDestination(destPage);
myMakeHyperlink(myFoundItems[i], myHyperlinkDestination);
myFoundItems[i].applyCharacterStyle(myHyperlinkStyle, false);
function myMakeHyperlink(myFoundItem, myHyperlinkDestination){
try {
var myHyperlinkTextSource = myDocument.hyperlinkTextSources.add(myFoundItem);
var myHyperlink = myDocument.hyperlinks.add(myHyperlinkTextSource, myHyperlinkDestination);
myHyperlink.visible = false;
catch(myError){
function myMakeHyperlinkDestination(myDestPage){
//If the hyperlink destination already exists, use it;
//if it doesn't, then create it.
try{
var myHyperlinkDestination = myDocument.hyperlinkDestinations.item(myDestPage);
myHyperlinkDestination.name;
catch(myError){
myHyperlinkDestination = myDocument.hyperlinkPageDestinations.add(myDestPage);
myHyperlinkDestination.destinationPage = myDestPage;
//myHyperlinkDestination.name = myDestPage.name;
//Set other hyperlink properties here, if necessary.
return myHyperlinkDestination;

Similar Messages

  • Trying to have a script work on all pages

      Hello,
    I am having a problem with my script in livecycle. I am trying to create random generated numbers, but the code i have only works on one page. I have 128 pages i need it to cover. The code is as follows. Please let me know if you have a solution. Oh and the boxes i have created are named the same throughout all of the pages. I tried setting everything to global, but that just produces the same numbers on each page. I would like to avoid having to write script for each page.
    Thanks
    topmostSubform.Page1.ButtonCreateCards::click - (JavaScript, client)
    var varN1 = Math.round(1 + (15-1)*Math.random());
    var varN2 = Math.round(1 + (15-1)*Math.random());
    while (varN2 == varN1)
    varN2 = Math.round(1 + (15-1)*Math.random());
    var varN3 = Math.round(1 + (15-1)*Math.random());
    while (varN3 == varN1 || varN3 == varN2)
    varN3 = Math.round(1 + (15-1)*Math.random());
    var varN4 = Math.round(1 + (15-1)*Math.random());
    while (varN4 == varN1 || varN4 == varN2 || varN4 == varN3)
    varN4 = Math.round(1 + (15-1)*Math.random());
    var varN5 = Math.round(1 + (15-1)*Math.random());
    while (varN5 == varN1 || varN5 == varN2 || varN5 == varN3 || varN5 == varN4)
    varN5 = Math.round(1 + (15-1)*Math.random());
    B1.rawValue = varN1;
    B2.rawValue = varN2;
    B3.rawValue = varN3;
    B4.rawValue = varN4;
    B5.rawValue = varN5;
    var varN1 = Math.round(16 + (30-16)*Math.random());
    var varN2 = Math.round(16 + (30-16)*Math.random());
    while (varN2 == varN1)
    varN2 = Math.round(16 + (30-16)*Math.random());
    var varN3 = Math.round(16 + (30-16)*Math.random());
    while (varN3 == varN1 || varN3 == varN2)
    varN3 = Math.round(16 + (30-16)*Math.random());
    var varN4 = Math.round(16 + (30-16)*Math.random());
    while (varN4 == varN1 || varN4 == varN2 || varN4 == varN3)
    varN4 = Math.round(16 + (30-16)*Math.random());
    var varN5 = Math.round(16 + (30-16)*Math.random());
    while (varN5 == varN1 || varN5 == varN2 || varN5 == varN3 || varN5 == varN4)
    varN5 = Math.round(16 + (30-16)*Math.random());
    I1.rawValue = varN1;
    I2.rawValue = varN2;
    I3.rawValue = varN3;
    I4.rawValue = varN4;I5.rawValue = varN5;

    I may not understand your problem completely. If you want all pages to have access to the same set of 5 random numbers, then use "variables" (that are global in scope--don't confuse this with setting field binding to global). You create "variables" (lets name them:  var1,var2, var3, var4, var5) in the form File>Form Properties>Variables tab. Then you reference them (say, from the calculation event of a numeric field) like this:
    this.rawValue = var1.value;  //rawValue for fields  .value for variables  (important)
    If you wanted just to be able to produce random numbers (a different set for each page/button) then a script object would be helpful
    This link explains in detail:
    http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000818.html#15866 93
    Briefly, you create a reusable function and store it in a Script Object (a place that all fields have access to). Then you reference that object, say on a button click. Lets say you have a script object named myScriptObject and you define a function on it called randomNumber()
    on the button click you can use that function by referencing it like this
    myScriptObject.randomNumber();
    So, with every click you run the script from any button on your form that has the reference above. Don't set the fields to Global and you'll get different results on the different pages
    You can pass defined parameters to the function inside the (), like if you needed to seed the random number generator function, you could pass a parameter like this:
    myScriptObject.randomNumber(someParameter);
    or multiple parameters
    myScriptObject.randomNumber(someParameter, [anotherOne],[YetAnotherOne],[etc.]);
    Your function can also set the values of variables, too. Seeing how I don't understand your objective completey, I don't know what parts of the above you'll find useful (if any).
    something like:
    function randomNumber()     {
         do some stuff;
         var1.value = something;
         var2.value = somethingelse;
         var3.value = etc;
    then
    myScriptObject.randomNumber();  //this reference placed on a button click, would update the variables
    and since the variables are global in scope, any script anywhere could access it.
    Is any of this helpful?
    Stephen

  • Make all pages the same width?

    I've seen several answers to this question but they all seem to involve using an external app such as PDF Creator, Distiller, or something like that.
    I have a pdf with three pages with different widths.  From within Acrobat X, what is the easiest way to make all three pages the same width, or is that even possible without using an external app?  If it is possible, please describe how to do this step by step.
    By the way, I know there are steps that can be taken to avoid ending up with pdf's that have pages of varying lengths, but this question is not about that.  It is about existing pdf's.  Thanks a lot
    I am using Adobe Acrobat X version 10.0.0.396 on Windows XP Pro SP3

    Good question - I would say make all the page be the same width as the widest one.  In general, these pdf's will contain 8.5" x 11" pages, sometimes in combination with legal size pages.  The actual size of each page will differ depending on such things as who they came from and how they produced the pdf's, what software was used, which scanner was used, etc.
    Here would be an example pdf:
    The first 3 pages approximately 8.5" x 11" format.  The last 2 pages are legal size.  As you page throgh the document, the widths change.  My usual setting as I page through a pdf is Fit Width.  But in this pdf, the first two pages look right, the third page is too narrow, the fourth page looks right, and the fifth page looks too narrow.  So given that, How would I make all 5 pages the same width so that as I page through the pdf, the widths are all exactly the same, and not just appear the same?  If I have to choose which width they should all be, I'd say go with the widest one.
    If I need to run some javascript to accomplish this, that's ok - I'll strip it out before distributing the pdf.  Thanks

  • Make all pages in safari 7 secure

    Is there an equivilant to HTTPS Everywhere put out by EFF.org?  With Mavericks and all the security issues always coming up, and with the release of 10.9.1 recently, I'm wondering if there's an extension(s) someone knows about that I can use make any page that's offered to ALWAYS be an SSL supported page? Thanks!

    You might also change the PDF to be full width or full page instead of a percent. If you set this in the document properties, then it should held as you move around. It may be that you are changing a particular page and then move around, meaning the new page goes back to the default set.

  • Make all pages viewable from default URL?

    I'm a bit confused about publishing to .Mac (as you can see from my other question.) I'd like my iWeb pages to be accessible along with my file-sharing page when I go to homepage.mac.com/myname. But when I go there, I only can see the file-sharing page. To get to my iWeb pages, I need to enter their very long, complicated, direct URLs. How can I fix this? Thanks.

    To
    get to my iWeb pages, I need to enter their very
    long, complicated, direct URLs.
    Your iWeb url is just this:
    http://web.mac.com/username
    You might want to use this and just link to your Homepage filesharing page via a hyperlink.

  • Scripts :EMail - gettiing 3 page data into 2 pages

    Hi all,
    I have created the layout using sap script for sales order and  when i see the print preview of sales order i can able to see th 3 pages in the layout in the NACE i have configured it to EMAIL so far i am getting email as per the design.
    Problem is that when  i click on print preview of email i can able to see all 3 pages of data  into 2 pages. half of second page data is displayed in first page which is not supposed to get on 2 pages , it should be displayed in 3 pages only.
    please help me out.
    Regards
    Venkat Boddu

    I dont think it will work....because as you said, it has wave type vector across all 5 pages then it is a single object which is not going to divide or split when moving pages.
    you have to manually divide the vector art in five section, put them on 5 pages ....and then when you will move the pages then artwork will move along the page.

  • Is there a way to make all page margins the same?

    I've exported a book file from indesign. Since the pages were in a book-type spread, the odd and even pages have different margins. The odd page has the bigger margin on the left, while the even has the bigger margin on the right.  Is there any way to make these identical after the fact. I can't go back and redo the indesign file.

    Thanks, there are 382 pages. Can't do them one by one.  And I purposely made the margins different in indesign, to give people more space in the middle.  The margins are as follows:
    But when I try to reverse the inside outside on one page of the spread, just reverse them, so the dimensions are the SAME, all the text and photos move.

  • How to make all pages in a PDF appear the same size?

    Hi, I am about to create many PDFs that show the bookmark pane and the document pane, with the document pane at 75%.
    If I create these PDFs to open as "single page continuous" and set the view at 75%, all scrolling is beautiful!
    But, if someone goes to a page by clicking a bookmark, the page views jump to a much larger size.
    How can I constrain the page view size to what I want?
    Karen

    You might also change the PDF to be full width or full page instead of a percent. If you set this in the document properties, then it should held as you move around. It may be that you are changing a particular page and then move around, meaning the new page goes back to the default set.

  • I always have to hit Control + 4 times to make all pages large enough to read and want to lock this size in on startup.

    Every time that I bring up FF on my 14" laptop, the page display is too small to read easily. I can go to (View) and "zoom" 4 times or hit (Control +) 4 times to give me a good sized page. I would rather have a (Option) choice that would save my personal setting for normal screen zoom for future uses of FireFox.

    The Firefox Page Zoom feature does a domain by domain level of saving the users preferred zoom level settings, there is no default Page Zoom level setting in Firefox.
    Try the Default FullZoom Level extension: <br />
    https://addons.mozilla.org/en-US/firefox/addon/6965
    Or the NoSquint extension: <br />
    https://addons.mozilla.org/en-US/firefox/addon/2592/

  • How to automatically make twitter @name fields into hyperlinks in Indesign?

    Hi folks,
       I have a book of tweets coming out and would like to publish Kindle, ePub and PDF versions of it, which would need hyperlinks throughout to work at all. So what I need is a way to automatically convert
    @Me
    into
    <A HREF="http://www.twitter.com/Me">@Me</A>
    as it were.
    There are about 1000 of them, so I don't want to have to do it manually!
    I have already used a GREP style to automatically format the @text (it's always one word, so it's easy) but the automatic hyperlink tool does not seem to allow customisation of what hyperlinks look like.
    Does anybody have any ideas as to the best way to approach this?
    Thanks,
    Ivan

    Hello John... Thanks.. My problem in large part stems from the way InDesign handles hyperlinks and what happens during the pdf process.. I have been having real problems with the "shared" destination default etc.. Anyways:  then I had to put in a twitter link and I couldn't find any clear description of how to do this in InDesign or the help community. I went around in circles.. The problem was with html tags.. and twitter exceptions and etc.. Anyways: the whole thing worked out after I spent many hours on the net.. mostly trying to find the right language to use to phrase the problem..  Not being a "tweeter" complicated issues.. (I had to do this for those who do tweet)... The answer, in short was this:
    get a retweet button;
    put retweet button in InDesign doc. 
    Post a tweet (in this case it was "Save the Date: HCV Training March 26, Houston TX  [link to permanent pdf of the training flyer]..
    Twitter will generate a short url.
    In Twitter, hover mouse over post and then "More" pops up
    Click on Embed
    Copy Embed code
    Paste embed code to text file
    Make URL hyperlink for retweet button and in the Destination put: http://twitter.com/share?text=Save%20The%20Date%20Houston%20March%2026&url=http://t.co/AQV rqixC0O
    Note: The above contains the message (after the text=) which must use %20 in lieu of any spaces in the text description.  Then after the &url= paste the short url that you copied from the embed code.
    Make sure that the InDesign link is NOT a shared destination and that it is a URL
    Save file and export to PDF
    As you can see... this took a while to figger out.. I found several posts on the internet but none stood alone... So here you go.

  • How to include a common java script in all pages to prevent browser closure

    We have already implemented a script to prevent accidentally browser closure. The script has been included in a js static file and loaded in APEX 4.01.
    There is a way to make the script available to all pages without including it in all pages ?
    Ad example to make an item available to all pages is sufficient to include it in page 0 there is somethings similar for java script
    Txs
    Giuseppe.

    Reference the script via a <tt>script</tt> element in the Header section of utilised page templates.

  • One script to make multiple cells call one function or vice versa

    Please help.
    I need one script to make multiple cells reference one function or one cell reference multiple functions.
    Goal: On the enter event of cell c1, I want to make cells (this, Header.c1, Example.c1, rLabel) highlighted, and this would be for every other cell that is entered into, their corresponding column header and row header will be highlighted.
    I've tried combining cells: eg
    colourControls.hdfieldLoseFocus(this, HeaderRow.c1, Example.c1, rLabel);
    and I've also tried combining some scripts in the function:
    fieldObj.ui.oneOfChild.border.fill.color.value = "255,255,200";
      HeaderRow.fieldObj.ui.oneOfChild.border.fill.color.value = "255,255,200";
      ExampleRow.fieldObj.ui.oneOfChild.border.fill.color.value = "255,255,200";
    But they dont work. See the link to my form.
    http://www.winstonanddavid.com/example.com
    I tried testing the function with the cell 'c1' but it doesnt work.
    Also, I want to get rid of the multiple lines of script in every other cell.
    How can I do this?

    I played around with the ExtendScript Toolkit and cutted and pasted the previous script from here until I managed to get a script that actually works like I was thinking. I then added a code from the CS4 Reference Manual to move Layer1 to the top (just to see if it worked).
    I have no idea yet if the the code includes something that does not belong, but at least I get no errors. The current code is like this now:
    //Apply to myDoc the active document
    var layerName = LayerOrderType;
    var myDoc = app.activeDocument;
    //define first character and how many layers do you need
    var layerName
    var numberOfLayers=0;
    //Create the layers
    for(var i=0; i<=numberOfLayers; i++)
    { var layerName = "Background";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
    { var layerName = "Picture";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
    { var layerName = "Text";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
    { var layerName = "Guides";  var myLayer = myDoc.layers.add(); myLayer.name = layerName;  }
    // Moves the bottom layer to become the topmost layer
    if (documents.length > 0) {
    countOfLayers = activeDocument.layers.length;
    if (countOfLayers > 1) {
    bottomLayer = activeDocument.layers[countOfLayers-1];
    bottomLayer.zOrder(ZOrderMethod.BRINGTOFRONT);
    else {
    alert("The active document only has only 1 layer")

  • How do I add scripts in order to make the page compatible with all the browsers.

    How do I add scripts in order to make the page compatible with all the browsers.

    As Jon says, please be more specific about "don't line up right"
    I notice you are inserting some arbitrary <BR> tags which will cause very unpredictable displays with varying user viewports and text preferences.
    <P>In 2008-2009, Families Forward benefited 278 homeless Philadelphia families, <BR>
      including 834 children. Families Forward assisted 1,413 stranded travelers, including <BR>
      235 children. In the first 6 months of 2009-2010, from July 1, 2009 to <BR>
      January 1, 2010, Families Forward assisted 185 homeless families and 220 <BR>
      stranded travelers.</P>

  • How to I make all the pages in a Pages document into pages, not sections, to I can drag specific pages around and place them where I need them? When I try to drag a specific page, it drags an entire section.

    How to I convert all the pages in a Pages document into simply pages, eliminating pages called "sections", so I can pick and chose specific pages to drag where I want (without dragging an entire section of pages)?

    Insert a Section Break at the foot of each page
    or:
    Toolbar > Document > Document > uncheck Document Body
    This will destroy any content in your document, but I presume that is what you want.
    Peter

  • Scripting to load all pdfs in a month into the place command?

    Hello, I was wondering if anyone knows of a script that allows for you to place all pdfs within a set date range from a folder into an InDesign document? I am looking to do my monthly report and each month I have to go out and get each one, would be nice to load the place tool with all the pdfs I have done with a set date range and then just place them accordingly. Is there something out there like this and/or am I missing something obvious?
    Thanks!
    B

    IM Sorry tomaxxi, am I suppose to be inputting something somewhere here in
    regard to the dates? I would need an example like for lets say the month of
    Nov. I try to paste this and save it in the script editor but it keep
    saying that the file cannot be saved. Any ideas? Please bear in mind your
    speaking to a guy who has like zero knowledge when it comes to scripts.
    Best regards,
    Robert
                                                                                    From:       tomaxxi <[email protected]>                                                                               
    To:         Robert Borchardt <[email protected]>                                                                               
    Date:       11/08/2010 03:29 PM                                                                               
    Subject:    Scripting to load all pdfs in a month into the place command?                                                                               
    Sorry for delay...
    I just tested script and it's working fine for me here.
    I created 4 sample PDF-s with just one page, then started script,
    selected exported PDF-s, script sorts them by creation date and loads
    placegun.
    So, all you need to do, is to start script and select documents you want to
    place.
    I changed script little, so make sure you use this one:
    if(app.documents.length != 0){
        var myFiles = File.openDialog("Select Files:", "*.pdf", true);
        if(myFiles != null){
            myFiles.sort(function ( a, b )
                    if ( a.created < b.created )
                        return -1;
                    if ( a.created > b.created )
                        return 1;
                    return 0;
            app.activeDocument.place(myFiles);
        }else{
            alert("No files selected!");
    }else{
        alert("No documents opened!");
    tomaxxi
    http://indisnip.wordpress.com/

Maybe you are looking for

  • MOVED: MSI Neo2-P network cable unplugged

    This topic has been moved to Off-Topic Technical. https://forum-en.msi.com/index.php?topic=96663.0

  • XI SOAP SocketException:There is no process to read data written to a pipe.

    Hi guys! I get this error and have no idea, where it comes from.. It occurs in scenario: SAR/3P->IntegrationProcess->SAPR/3, wher in integration process I map r/3 message to soap call synchronously external web service, map soap response to target sa

  • Mail spell check

    When I am spell checking an email prior to sending, if I want to go back to modify the text, the document is sent if I press return. How do I modify the body of a document once in spell check? Related to this, how do I cancel out of spell check once

  • JSP Compiler and CLASSPATH

     

  • Merging application systems between workareas

    Hi, We have a number of application systems with shares to and fro and these should be migrated to designer 6i. During a pilot one of these application systems is migrated. Now the rest has to be migrated and we come across a "problem". During the tr