Skip to content

Commit 519d5c6

Browse files
committed
docs: add direct answer to range request
1 parent 58fa925 commit 519d5c6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

docs/cookbook/index.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@ You can set [`textLayerMode`](/learned-knowledge/#textlayermode) option to 0 to
1717

1818
## How to setup `Range Request` only download necessary data?
1919

20-
See the comment by me in the [discussion](https://github.com/mozilla/pdf.js/discussions/18524#discussioncomment-10202877).
20+
The `Range Request` only works if you use the default pdf.js viewer. if not, you have to implement all by yourself to
21+
support `Range Request`. Even if you use the default viewer, the server must also be configured to
22+
support [Range Request](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) correctly.
23+
24+
For those who already use the default viewer and still suffer this issue, go through the checklist to ensure your server was configured correctly:
25+
26+
- Make sure you didn't set the `disableRange` option
27+
- Make sure the first get request that downloads the pdf return 200 or 206.
28+
- Make sure the first get request has the right `Content-Length`, `Accept-Ranges` and `Content-Encoding` header
29+
- The `Content-Length` should be larger then `2 * rangeChunkSize`, the default [rangeChunkSize](https://github.com/mozilla/pdf.js/blob/f6b356eff753358bf3263d174dc0cf4852800edd/src/display/api.js#L76C7-L76C31) is 65536
30+
- The `Accept-Ranges` should be `bytes` and the server must really support it
31+
- The `Content-Encoding` should be `identity` if present
32+
33+
If you ensure all these were configured correctly, then you can debug the code block step by step to find out what's the real issue.
34+
35+
https://github.com/mozilla/pdf.js/blob/f6b356eff753358bf3263d174dc0cf4852800edd/src/display/fetch_stream.js#L130-L168
36+
37+
I posted a similar comment in [discussion](https://github.com/mozilla/pdf.js/discussions/18524#discussioncomment-10202877).

0 commit comments

Comments
 (0)