mupdf.js has reported an issue where Link Destinations are not correctly created when one coordinate is left out. let outlineItem = { title: 'demo', uri: doc.formatLinkURI({ page: 0, type: 'XYZ', y: 200, }), open: false, } console.log(outlineItem) // { title: 'demo', uri: '#page=1&zoom=nan,nan,200', open: false } // this looks ok doc.outlineIterator().insert(outlineItem) console.log(doc.outlineIterator().item()) // { title: 'demo', uri: '#page=1', open: false } // x,y coordinates are lost unless both are set
I have reproduce this in mutool run using a script: var doc = Document.openDocument("doc.pdf"); print(doc); var iter = doc.outlineIterator(); print(iter); var dest = { page: 10, type: 'XYZ', y: 200, }; print(dest); var ourrll = doc.formatLinkURI(dest); print(ourrll); var item = { title: 'demo', uri: ourrll, open: false, }; print(item); var res = iter.insert(item); print(res); doc.save("out.pdf", "incremental"); res = null; item = null; ourrll = null; dest = null; iter = null; doc = null; gc(); After executing the script and looking at out.pdf: $ mutool show out.pdf trailer.Root.Outlines.First 87 0 obj << /Parent 3 0 R /Title (demo) /Dest [ 71 0 R /XYZ null null null ] >> endobj
Alright this clusters and pymupdfs well. Off to review, during which there are bound to be a few comments as my proposed code is not really nice. Maybe the fix should be _inside_ fz_transform_point_xy()?
Indeed there was comments during review, thus this was fixed by commit 352234290008fdf093b3c396f375fdef6de91121 Author: Robin Watts <Robin.Watts@artifex.com> Date: Tue Jun 11 09:15:49 2024 +0100 Bug 707822: Take missing coordinates into account when creating link dest. Previously if either coordinate was NaN, then after transformation both coordinates would be NaN. But it is desired for given coordinates to be transformed while missing coordinates are kept at NaN. From an original patch by Sebastian.