View first page before entire document is loaded - support range header
See original GitHub issueBefore you start - checklist
- I have read documentation in README
- I have checked sample and test suites to see real life basic implementation
- I have checked if this question is not already asked
What are you trying to achieve? Please describe.
In our project (issue, demo), I’d like to load only the pages that I’m viewing, and render the first page before the entire document is loaded.
From my understanding, PDF.js supports Range headers and the react-pdf
API describes that it’s possible to include a PDFDataRangeTransport
object in the file
property. I fail to see what to do to actually send these Range headers, though!
Describe solutions you’ve tried
- Check if the source PDF is optimized for the web
- Check if the hosting service supports HTTP Range headers
Environment
- Chrome 75
- MacOS 10.14.5
- React-PDF 4.0.5
- React-scripts 3.0.1
- React 16.8.6
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
HTTP range requests - MDN Web Docs - Mozilla
An HTTP range request asks the server to send only a portion of an HTTP message back to a client. Range requests are...
Read more >How to get byte range of PDF pages? - Stack Overflow
I'm currently using XAMPP on my system, and I'm not sure if XAMPP supports range requests (to test), although the site will be...
Read more >How CloudFront processes partial requests for an object ...
If the origin doesn't support Range GET requests: It returns the entire object. CloudFront serves the current request by sending the entire object...
Read more >Progressive loading - MuPDF
The idea of progressive loading is that as you download a PDF file into a ... the first page of a document in...
Read more >Page Speed Metrics - FullStory Support
More specifically, the DOMContentLoaded fires when the initial HTML document has been loaded and parsed. Often this milestone occurs before stylesheets, images, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
According to PDF.js developers, PDF.js does not support
gzip
encoding of range responses, so it needs to be set explicitly. According to the PDF.js docs, you can set custom headers. Since Document passes theoptions
object toPDFjs.getDocument
, this should work:However, it does not, so I’m still investigating what is going on. It seems likely that it’s a pdf.js issue.
@joepio Well I finally managed to do it, it was failing because our backend implementation was not compatible with
pdf.js
Frontend component
Backend implementation (in Python)
I would strongly recommend reading the Range Requests RFC https://datatracker.ietf.org/doc/html/rfc7233 to understand everything, there are a few gotchas