We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add bookmark to a pdf file and in an accurate location

HI all
I have a feature for adding bookmark to a PDF file, but I found when I click the bookmark, I cann’t located the accurate line to the content.

I tried all the destination I found, but I didn’t do it successfully. Could you give me some advice for it?
double zoom = 1;
Page item = pdfDocument.getPages().get_Item(i);
GoToAction action = new GoToAction(new XYZExplicitDestination(item, textFragment.getPosition().getXIndent(), textFragment.getPosition().getYIndent(), zoom));
// setting action to fit to page width zoom
// GoToAction actionFittoWidth = new GoToAction(new FitHExplicitDestination(item, item.getMediaBox().getWidth()));
// // setting action to fit to page height zoom
// GoToAction actionFittoHeight = new GoToAction(new FitVExplicitDestination(item, textFragment.getPosition().getYIndent()));

// GoToAction action = new GoToAction(new FitHExplicitDestination(pdfDocument.getPages().get_Item(i), textFragment.getPosition().getYIndent()));
// textFragment.getPosition().get
// GoToAction action = new GoToAction(new FitHExplicitDestination(pdfDocument.getPages().get_Item(i), textFragment.getPosition().getYIndent()));
pdfOutline.setAction(action);
// pdfOutline.setAction(new GoToAction((Document) pdfDocument.getPages().get_Item(i).getDocument(), bookmark));
// pdfOutline.setDestination(pdfDocument.getPages().get_Item(i).getDocument().getDestinations());
Thanks
Lisa

@LisaZe001

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input PDF.
  • Please attach the output PDF that shows the undesired behavior.
  • Please create a sample Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

That’s my code and pdf source file.addBookMark.7z (91.2 KB)

Thanks for your reply.

@LisaZe001

Please also share these resources here for testing. Thanks for your cooperation.