Bookmarks created in code appear in reverse order

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

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

jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Bookmarks created in code appear in reverse order

Post by jeffp »

I'm using the following code to add a bookmark to by PDF. However, they are appearing in reverse order. That is, the first bookmark I create appears at the end of the list and last one I create appears first in the list.

When I create them manually while in the ViewerAX interface, they are listed in the order I create them.

Code: Select all

procedure TPDFViewerAX.AddBookmark(ADocID, APage: Integer; ATitle: String);
var
  js, AStr: WideString;
begin
  if not IsValidDocID(ADocID) then exit;

  try
    js := Format('this.bookmarkRoot.createChild("%s", "this.pageNum=%d");', [ATitle, APage - 1]);
    FControl.RunJavaScript(js, AStr, ADocID, 0);
  except end;
end;
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Bookmarks created in code appear in reverse order

Post by Tracker Supp-Stefan »

Hello jeffp,

The createChild method can take up to 3 parameters - the third one being:
nIndex (optional) The 0-based index into the children array of the bookmark at which to create the new child. The default is 0.
So when you do not specify it - all new bookmarks are always placed on top as the first bookmark in the tree. Please take a look at page 178 here.

Regards,
Stefan
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Bookmarks created in code appear in reverse order

Post by jeffp »

Ok. I see that I was using a default of 0 for the index.

Now, there is one other issue I'm having with Bookmarks. If I set a bookmark using that same js code and set it to page 1. I then manually prepend a new page to the pdf. The bookmark stays at page 1. I'd expect the bookmark to follow the page that I assigned it to even when that page changes its order.

Is there a way to do this. I think this is the way it works if I manually create a bookmark in the UI.

--Jeff
User avatar
Lzcat - Tracker Supp
Site Admin
Posts: 677
Joined: Thu Jun 28, 2007 8:42 am

Re: Bookmarks created in code appear in reverse order

Post by Lzcat - Tracker Supp »

Hi Jeff.
All working as expected: you add bookmark with JS action goto page with specified number, so whet you click on it script find page with specified number. But when you create bookmark using UI default action is GoTo, and it refer to page object, not using page number. This is why bookmartk with JS action and GoTo action behave different when you insert/remove/reorder pages.
HTH
Victor
Tracker Software
Project manager

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Bookmarks created in code appear in reverse order

Post by jeffp »

So I guess what I'm asking is there any way to set a bookmark in code (not manually) that would assign the bookmark to a page object instead of a page number? Can this be done in JS? Or is there another way.

I see I can do this with the SDK DLL, but I need to be able to set bookmarks in an opened ViewerAX file via code.

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

Re: Bookmarks created in code appear in reverse order

Post by Tracker Supp-Stefan »

Hello Jeff,

The JS API does not contain the needed methods to do that - so unfortunately it's not possible via JS alone.
You can indeed do it with the PDF Tools SDK, or with the Editor SDK, and we would recommend the Editor SDK as this will allow you to both have the file displayed, and have full control over it and perform the needed modifications and bookmarks creation via code:
https://www.pdf-xchange.com/product/pd ... editor-sdk

Regards,
Stefan