[javascript FR] Add a bookmark/link through javascript that updates with inserted pages

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Mathew
User
Posts: 239
Joined: Thu Jun 19, 2014 7:30 pm

[javascript FR] Add a bookmark/link through javascript that updates with inserted pages

Post by Mathew »

When adding bookmarks though javascript, the only way I can see to make the bookmark do something is to add a javaScript to it with .createChild( cName, cScript, nIndex) or .setAction( cScript )

This works fine until a page is moved, inserted, or added - the bookmark then points to the wrong page. Is there a way to add a goto page action that PDF XChange will recognize and update as it does when you add a bookmark through the bookmarks pane?

Digging a bit deeper, when I export bookmarks to a text file (Bookmarks > Export Bookmarks to Text file...) the resulting text file shows nothing for the javascript action. What would be really fantastic would be a goto method on bookmarks that could get/set the goto parameters that show up when bookmarks are exported to text:

Code: Select all

To pg 5; goto:{4; Fit; 15}
SSK-03; goto:{2; XYZ; 12; 792.000; 612.000}
Added by javaScript
Last edited by Mathew on Fri Mar 22, 2024 8:28 pm, edited 1 time in total.
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8624
Joined: Wed Jan 03, 2018 6:52 pm

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by TrackerSupp-Daniel »

Hello, Mathew

I have passed this along to the Dev team and am just awaiting a reply on how doable this is. Hopefully we can get a positive response and I can go make a ticket, I will keep you posted when they reply.

Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 239
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by Mathew »

In the PDF Reference v1.7 it lists two options for bookmarks and links. Only A (action) is currently accessible by javascript. Actions are very hard (maybe impossible) to parse and update automatically.

This request is that Dest (destination) also be accessible by javascript (read and write).
image.png
Destination object/array should follow the PDF Reference:
image(1).png
image(2).png
This would open up the possibility of scripts that could add links or bookmarks within documents based on the contents of the document. These links/destinations wouldn't be fragile and break any time a page is added or removed because PDFXChange already updates destinations.
You do not have the required permissions to view the files attached to this post.
Mathew
User
Posts: 239
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by Mathew »

The specific use case I'm looking at right now is this (in the Architecture/Engineering field):

Permitting authorities in many jurisdictions in the USA are starting to require that pdf drawing sets submitted to them have both bookmarks for all the sheets, with the name and number of the drawing, and links from individual references within the drawings to the referenced sheet.

This is tedious to do by hand, but an automated tool can do it relatively easily. The problem is that if done in javascript that tool would have to add actions to the bookmarks and links. But when drawings from all sub-consultants are combined in a set, all those actions would break (they'd point to the wrong page). For a javascript tool to be able to do it, it would need to set the Dest property.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by Tracker Supp-Stefan »

Hello Mathew,

Unfortunately the JS Bookmark methods are quite limited:
image.png
You can not really access or modify the existing actions. You can overwrite them by setting new Action for a bookmark, however you can not read them first so that you can e.g. modify them before overwriting.

However - have you tried setting a "gotoNamedDest" as the action for your bookmarks? You will probably still need to create the named destinations manually, but then once a bookmark is set to point to a Named Destination - that destination moves with the page - so even if the order of pages changes - your bookmark link will still work?

Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
Mathew
User
Posts: 239
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by Mathew »

Yes: I guess I should have titled it "javascript Feature Request": Add methods .getDestination() and .setDestination() to bookmark methods.

There have been a few other posts asking for similar functionality (find the destination of bookmarks in javascript - currently there's only a hack workaround that has a number of problems).
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8624
Joined: Wed Jan 03, 2018 6:52 pm

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by TrackerSupp-Daniel »

Hello, Mathew

Thanks for clarifying, I spoke with the team and this one is a low priority request, so no timeline other than "unlikely to be soon":
RT#6841: FR: add .getDestination() and .setDestination() JS methods for bookmarks

Kind regards,
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 239
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] Add a bookmark through javascript that updates with inserted pages

Post by Mathew »

Thank you!

It's a similar situation for Links - but there's no workaround I know to even find their destination:
image.png
:D

Bookmarks and Links are very similar, and would be ideal items for scripting because there are often so many of them and making changes is such a huge tedious task. Yet without this functionality, javascript is almost useless on them.
You do not have the required permissions to view the files attached to this post.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: [javascript FR] Add a bookmark/link through javascript that updates with inserted pages

Post by Tracker Supp-Stefan »

Hello Mathew,

I've just updated the ticket to make the request to also work for Links - I can't tell you yet whether that is possible and whether it can be in the same ticket - but if it needs a separate one - I will create it. For now the ticket is:
#6841: FR: add .getDestination() and .setDestination() JS methods for bookmarks and links

Kind regards,
Stefan
Mathew
User
Posts: 239
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript FR] Add a bookmark/link through javascript that updates with inserted pages

Post by Mathew »

:wink: thank you.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

[javascript FR] Add a bookmark/link through javascript that updates with inserted pages

Post by Tracker Supp-Stefan »

:)