ArtifexSoftware / mupdf.js

JavaScript bindings for MuPDF
https://mupdfjs.readthedocs.io
GNU Affero General Public License v3.0
371 stars 22 forks source link

document.resolveLink returns only page index rather than link destination object #86

Closed King-of-Infinite-Space closed 4 months ago

King-of-Infinite-Space commented 4 months ago

According to the documentation, document.resolveLink gives a Link Destination Object. But currently it only returns the page index.

I was hoping to resolve the uri of an outline item, e.g. #nameddest=section.1, to get the coordinates. A possible workaround is link.getBounds() but resolveLink would be much more convenient.

jamie-lemon commented 4 months ago

@King-of-Infinite-Space I'm wondering if the documentation for mupdf.js has neglected to mention the loadOutline method - https://mupdf.readthedocs.io/en/latest/mutool-run-js-api.html#loadOutline , if I understand correctly you want to get the uri of the outline items?

King-of-Infinite-Space commented 4 months ago

I have the uri of the outline item but want to use resolveLink(uri) to get the coordinates to navigate to the exact location.

jamie-lemon commented 4 months ago

Aha - I understand the issue now - I can confirm I see the same problem - indeed it doesn't return the full link destination object (i.e. https://mupdf.readthedocs.io/en/latest/mutool-run-js-api.html#mutool-run-js-api-link-dest) - this is a bug that requires fixing.

jamie-lemon commented 4 months ago

@ccxvii Are you able to look into this? e.g.

let linkDestination = doc.resolveLink("#nameddest=section.1.2");
console.log("linkDestination="+linkDestination); 

Prints a numeric of the page index, but we are expecting a link destination object.

ccxvii commented 4 months ago

commit 711b2ca263209db941c89b5ac1710e73fb3032ca adds the resolveLinkDestination function that returns the full link information.

jamie-lemon commented 3 months ago

@King-of-Infinite-Space Please note this fix is now available on NPM with version 0.2.2 - https://www.npmjs.com/package/mupdf , docs also updated here: https://mupdfjs.readthedocs.io/en/latest/how-to-guide/node/annotations/links/index.html#resolving-internal-links