Page range generation fails due to structures
Closed this issue · 2 comments
If a user requests a range of pages for a manifest that contains structures
(a.k.a. table of contents for the generated PDFs) then PDF generation will fail if any on the canvases present in the structures
are not also included in the requested page range.
The effect is that a "Could not find canvas with id XXX in manifest!" error is thrown in the _addOutline method, which causes PDF generation to fail.
Steps to reproduce
Visit the demo site and use the sample Book-with-TOC manifest
https://iiif.io/api/cookbook/recipe/0024-book-4-toc/manifest.json - if you select any page range other than 1-6 then it will fail, given that all six pages are referenced in the structures
array.
Sharing a potential solution for consideration, something along these lines:
In generator.ts
, the _addOutline()
method is expected to return an array that contains a pdfObject
and a number
. Update the types so that it can return an array or null
, and instead of throwing inside _addOutline()
return null
. In the setup()
method, we should be able to test if the return value from _addOutline()
is null
and use continue;
to skip over it. We might also need to look at the recursive call for _addOutline()
.
My only concern might be that I'd like to better understand if this would effect the original intent of the commit which added the throw
.
Either way I'm happy to open a PR to address this issue.
I just pushed a fix for this, thanks for reporting the issue @tristanr-cogapp and for the suggestions @jonw-cogapp!
I fixed it before passing in the parsed outline to the PDF generator, at that point we can already decide which ranges have no corresponding canvases and throw them out during the build of our TocItem[]
list.