Updating the destination page of existing bookmark using Aspose.pdf for java

Hi,

I am trying to update the destination page in an existing pdf document using the following code.

Bookmarks bookmarks = bookmarkEditor.extractBookmarks();
int ii=0;
for(Bookmark bookmark : (Iterable)bookmarks)
{
com.aspose.pdf.OutlineItemCollection pdfOutline = new com.aspose.pdf.OutlineItemCollection(doc.getOutlines());
if(bookmark.getTitle().equalsIgnoreCase(“Test”))
{
pdfOutline.setDestination(new com.aspose.pdf.GoToAction(8));
doc.getOutlines().get_Item(5).add(pdfOutline);
}
}

The above code does not work. I need to reset the page for existing bookmark since I added a new page in the pdf document and this has changed the page number.

Is there any solution or a workaround.

Best Regards

Hi Rajeev,


Thanks for contacting support.

In order to reset/update the bookmark destination page, please try using the following code snippet. The following code snippet demonstrates the steps to update the destination page number for first bookmark.

[Java]

//open document

Document pdfDocument = new Document("c:/pdftest/BookmarkInheritZoom.pdf");

//get a bookmark object

com.aspose.pdf.OutlineItemCollection pdfOutline = pdfDocument.getOutlines().get_Item(1);

// set the target page as 10

pdfOutline.setDestination(new com.aspose.pdf.GoToAction(10));

//save output

pdfDocument.save("c:/pdftest/Bookmarkupdated_output.pdf");