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

Free Support Forum - aspose.com

How to get the bookmark's zoom property using Aspose.PDF for java

How to get the bookmark’s zoom property using Aspose.PDF for java like the following picture.
p1.png (21.4 KB)

@wusk

We need to investigate this requirement of yours. However, could you please share a sample PDF document for our reference. We will further proceed to assist you accordingly.

Thank you for your help !
The attachment is the corresponding PDF file and the position of the bookmark zoom property.
Looking forward to your reply.
test.pdf (63.3 KB)
p1.png (63.8 KB)

@wusk

We tried below code snippet and were not able to get the zoom value for the bookmark. The API threw an Exception.

Document document=new Document(dataDir + "test.pdf");
for(OutlineItemCollection itemCollection:document.getOutlines())
{
 double zoom = ((XYZExplicitDestination)itemCollection.getDestination()).getZoom();
 System.out.println(zoom);
}

Therefore, an issue has been logged as PDFJAVA-40124 in our issue management system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you very much for your help and look forward to your results

@wusk

We will surely investigate the logged issue on a first come first serve basis and inform once additional updates are available regarding ticket resolution.

@wusk

We have investigated the earlier logged ticket. In the attached document direct destination is empty. But the PdfAction consists 2 destinations (it can be even more). Also there are no zoom value because it is using FitHExplicitDestination, not XYZExplicitDestination.

The following code shows how to get values of those bookmarks:

Document document=new Document(dataDir + "test.pdf");
        for(OutlineItemCollection itemCollection:document.getOutlines())
        {
            IAppointment destination = itemCollection.getDestination();
            if (destination !=null) {
                if (destination instanceof XYZExplicitDestination) {
                    double zoom = ((XYZExplicitDestination) destination).getZoom();
                    System.out.println("zoom: " + zoom);
                }
            }

            PdfAction action =  itemCollection.getAction();
            if (action!=null){
                if (action instanceof GoToURIAction)
                    System.out.println("URI: " + ((GoToURIAction)action).getURI());

                ActionCollection actionCollection = action.getNext();
                if (actionCollection !=null) {
                    System.out.println("Extra actions size: " + actionCollection.size());
                    if (actionCollection.size() == 1) {
                        PdfAction internalAction = actionCollection.get_Item(1);
                        if (internalAction instanceof GoToAction) {
                            IAppointment destination2 = ((GoToAction) internalAction).getDestination();
                            if (destination2 != null) {
                                if (destination2 instanceof XYZExplicitDestination) {
                                    double zoom = ((XYZExplicitDestination) destination2).getZoom();
                                    System.out.println("zoom: " + zoom);
                                }
                                if (destination2 instanceof FitHExplicitDestination) {
                                    System.out.println("Destination page: " + ((FitHExplicitDestination) destination2).getPage().getNumber());
                                    System.out.println(
                                            "Represents explicit destination that displays the page with the vertical coordinate top " +
                                                    "positioned at the top edge of the window and the contents of the page magnified just enough to " +
                                                    "fit the entire width of the page within the window.");
                                }
                                //can be other destination types
                            }
                        }
                    }
                }
            }
        }