pdf.js: total is undefined in LoadingTask.onProgress
Attach (recommended) or Link to PDF file here: https://jsfiddle.net/p3ybwp7d/1/
Configuration:
- Web browser and its version: Google Chrome - Version 62.0.3202.75
- Operating system and its version: Mac OS 10.13
- PDF.js version: 1.10.97
- Is a browser extension: No
Steps to reproduce the problem:
Create loading task and add onProgress callback:
let loadingTask: any = PDFJS.getDocument(this.src);
loadingTask.onProgress = (progressData) => {
// progressData won't contain "total", only "loaded"
};
What is the expected behaviour? (add screenshot)
In previous versions, onProgress did return both total and loaded.
What went wrong? (add screenshot)
total field is undefined in loadingTask.onProgress callback.
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension): https://jsfiddle.net/p3ybwp7d/1/
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (12 by maintainers)
It’s related to
fetch, since you can observe the same issue in Firefox too (with thedom.streams.enabledandjavascript.options.streamsprefs set inabout:config).We just updated to 1.10.97 which broke our loading task. As a (hopefully temporary) workaround, we do a header-only fetch for the content-length header beforehand:
Hi! My first comment in GitHub, sorry if I make a mistake. I kind of found a solution: The suggestedLength of returnValues is never really updated with the length calculated.
So I did:
returnValues.suggestedLength = length ; , before any “if” .
Also the Http header must match, so attention with Content-Length and Content-length (case sensitive)
First we are setting
PDFNetworkStreamat https://github.com/mozilla/pdf.js/blob/237bc2ef9df204069c4996e14433e0a35123444a/src/pdf.js#L35-L45based on the environment and support for stream. So if streaming is supported by the browser then
PDFNetworkStreamisPDFFetchStream.After this we are calling this constructor with all the provided
paramsfrom: https://github.com/mozilla/pdf.js/blob/237bc2ef9df204069c4996e14433e0a35123444a/src/display/api.js#L255If you want to see what these
paramsare, you can read here: https://github.com/mozilla/pdf.js/blob/237bc2ef9df204069c4996e14433e0a35123444a/src/display/api.js#L98-L140