Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Scripting Prev/Next Hyperlinks on frame

Return to Member Forum

  • Author
    Posts
    • #68825

      Having to create and set hyperlink on frames by frame to enter the page destination can be really time consuming on a long document. I wonder if a script have already been developed to automate this process, probably base on name of object.

      Anyone have seen this king of script?

      Thanks

    • #68980

      Can you expand a bit on what you need? I don’t know if it already exists in the form and shape you want, but it reminds me of the “Continued on page xx” script I wrote a while ago: https://creativepro.com/how-to-add-automatic-jump-lines.php

      • #68984

        hi Jongware…

        It fact, it’s about creating a PDF with hyperlinks «zone» on frame that will be use as go to next page, go to previous page. This can be done easily with buttons, but buttons is not supported 100% on all mobile app. So the need to use Hyperlinks instead. But they require you to manually enter the destination page number. On a few page, that’s fine, but on a 100 pages doc, that’s boring & painful to do. So the need to automate this process.

        Either with identified object with specific object styles, or else.

        JC

    • #68987

      Okay, here is something I made up right now. Try to run it only once per document :P as it attempts to ‘clean up’, but hyperlinks may use so many different objects, it’s hard to get that right.

      All it requires are objects marked with one of two object styles: ‘prev’ and ‘next’. The objects may appear on any single page, or reside on a Master Page. Only one level deep! That is, not on a master page based on a master page, which in turn is based on a master page … (and so on) … Keep it simple!

      After running the script, master page items are overridden, and all ‘prev’ objects will link to the previous page and ‘next’ to the next one. A ‘prev’ link on the first page will not get linked, and neither will a ‘next’ link on the *last* page of a document.

      Here is the code; also downloadable from my site as https://www.jongware.com/binaries/linkprevnextpages.zip

      //DESCRIPTION:Make Page To Page Links
      // A Jongware script 13-Jun-2014
      // Do not modify or distribute without permission.

      for (p=0; p < app.activeDocument.pages.length; p++)
      processPage(app.activeDocument.pages[p]);

      function processPage (a_page)
      {
      var obj, link, e;

      /* search the applied master */
      if (a_page.appliedMaster != null)
      {
      for (obj=0; obj<a_page.appliedMaster.pageItems.length; obj++)
      {
      if (a_page.appliedMaster.pageItems[obj].appliedObjectStyle)
      {
      if (a_page.appliedMaster.pageItems[obj].appliedObjectStyle.name == ‘prev’ &&
      a_page.documentOffset > 0)
      {
      try {
      a_page.appliedMaster.pageItems[obj].override (a_page);
      } catch (e)
      {
      /* no problem */
      }
      }
      if (a_page.appliedMaster.pageItems[obj].appliedObjectStyle.name == ‘next’ &&
      a_page.documentOffset < app.activeDocument.pages.length-1)
      {
      try {
      a_page.appliedMaster.pageItems[obj].override (a_page);
      } catch (e)
      {
      /* no problem */
      }
      }
      }
      }
      }

      /* check current objects */
      for (obj=0; obj<a_page.pageItems.length; obj++)
      {
      if (a_page.pageItems[obj].appliedObjectStyle)
      {
      if (a_page.pageItems[obj].appliedObjectStyle.name == ‘prev’ &&
      a_page.documentOffset > 0)
      {
      removeOldLink (a_page.pageItems[obj]);
      link = app.activeDocument.hyperlinks.add (app.activeDocument.hyperlinkPageItemSources.add(a_page.pageItems[obj]),
      app.activeDocument.hyperlinkPageDestinations.add(app.activeDocument.pages[a_page.documentOffset-1]) );
      link.visible = false;
      }
      if (a_page.pageItems[obj].appliedObjectStyle.name == ‘next’ &&
      a_page.documentOffset < app.activeDocument.pages.length-1)
      {
      removeOldLink (a_page.pageItems[obj]);
      link = app.activeDocument.hyperlinks.add (app.activeDocument.hyperlinkPageItemSources.add(a_page.pageItems[obj]),
      app.activeDocument.hyperlinkPageDestinations.add(app.activeDocument.pages[a_page.documentOffset+1]) );
      link.visible = false;
      }
      }
      }
      }

      function removeOldLink (pageitem)
      {
      var i, hpis = app.activeDocument.hyperlinkPageItemSources, l = hpis.length;
      for (i=0; i<l; i++)
      {
      if (hpis[i].sourcePageItem == pageitem)
      {
      hpis[i].remove();
      return;
      }
      }
      }

    • #68988

      Jongware… This is working perfectly! Just tried it on a 200 pages.

      Are you going to make it available somewhere or even ask David or Anne-Marie to post about it?

      Much appreciated you help. I’m sure a lot of folk can benefits from it.

      Jean-Claude

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Forum Ads