johnfactotum / foliate-js

Render e-books in the browser
https://johnfactotum.github.io/foliate-js/reader.html
MIT License
375 stars 56 forks source link

Can the pdfjsLib use random access of `File` to parse and render PDF document? #37

Open chrox opened 1 day ago

chrox commented 1 day ago

The EPUB parser and renderer has a reasonably low memory footprint by random accessing document file which is neat. I wander if this can be adapted to pdf-js which for now reads the whole file into a ArrayBuffer even just for parsing the document metadata.

johnfactotum commented 1 day ago

I've wondered this myself. From https://github.com/mozilla/pdf.js/blob/e1f9fa4ea54246bbfa974ac75720793b9ff9fd12/src/display/api.js#L117, it says it only accepts TypedArray | ArrayBuffer | Array<number> | string. But it does support HTTP range requests if you give it a URL. Perhaps one should ask the PDJ.js devs.

chrox commented 6 hours ago

Nice hint. I will try the HTTP range way.

chrox commented 4 hours ago

Awesome. It works like a charm. image