Copy link to clipboard
Copied
I made the following post a few days ago: Re-Order Pages to Match Bookmarks, but I have now run into a different problem related to the same project. I was able to get the pages re-ordered to match the order of the bookmarks by doing the following:
PDDocInsertPages(newDocument, moveAfterPage, originalDocument, currentPageNumber, 1, includeFlags, NULL, NULL, NULL, NULL);
PDDocReplacePages(originalDocument, 0, newDocument, 0, PDAllPages, true, NULL, NULL, NULL, NULL);
However, now that the pages have been re-ordered, the destination page for each bookmark is incorrect. I have pages labeled 1 through 10. I moved page 7 to be the second page in the document, so the order is 1-7-2-3-4-5-6-8-9-10. But now the bookmark for "page 7" still points to the page at position 7 (which is now the page labeled "6") rather than pointing at the page labeled "7" (which is now the second page in the document).
Is the problem coming from the way that I re-ordered the pages in the 3 steps listed above?
Is there a way to force the bookmarks to update their destination as a page is moved to a new position?
Or is there a way to manually update the destination page for a bookmark when I move the page to a new position?
I have looked in the Acrobat API documentation, but I have not been able to find a way to do either of these.
Copy link to clipboard
Copied
Use named destinations for this. Create named destinations on the pages and use the named destinations in the bookmarks.
Then you can move the pages and the bookmarks will always point to the correct page.
Copy link to clipboard
Copied
Ok I was able to remove the old action from the bookmark:
PDBookmarkRemoveAction(myBookmark);
But I'm having trouble adding a named destination to the bookmark. Here is what I have tried:
// create a name tree to store all of the named destinations
PDNameTree nameTree = PDNameTreeNew(originalDocument);
// the key/value for the named destination
char* name = bookmarkTitle;
char* value = bookmarkTitle;
// get the cos doc for the current document
CosDoc myCosDoc = PDDocGetCosDoc(originalDocument);
// create key/value pair for the current named destination
CosObj cosObjKey = CosNewString(myCosDoc, false, name, strlen(name));
CosObj cosObjValue = CosNewString(myCosDoc, false, value, strlen(value));
// add the named destination to the name tree
PDNameTreePut(nameTree, cosObjKey, cosObjValue);
But I do not see any destinations when I open the "Destinations" panel in acrobat.
And I don't see how to add the destination to a bookmark (using the Acrobat SDK) once the destination is successfully added to the document.
I'm sorry for asking these seemingly basic questions, but what am I missing?
Copy link to clipboard
Copied
Add a destination to the document and use the destination in a bookmark. After this look at the internal structure of the PDF.
Copy link to clipboard
Copied
I understand what needs to be done, but right now I am unable to add a destination to the document. The code above was my attempt at doing so, but there are still no destinations in the document after executing that code.
Can you point me in the direction of the corresponding API documentation? Or tell me if my code is on the right track? Or am I coming at it from the wrong angle? I can't find anything by searching "named destination".
I am somewhat familiar with the PDViewDestination
object, but I'm not sure if that's what I need here.
Copy link to clipboard
Copied
In the PDF Reference look for "named destination".
Copy link to clipboard
Copied
Your code looks like it creates a name tree but does not store it into the PDF. A PDF may contain multiple name trees but the named destination tree is stored in a particular place (probably the catalog object)
Copy link to clipboard
Copied
Due to an approaching deadline and my unfamiliarity with named destinations, I have decided to go a different route. Instead, I am simply updating the GoTo action for each bookmark to reference the new page locations.
Thank you for your help.