Pdf.js: PDF total-Size undefined when loading

Created on 28 Jun 2016  路  2Comments  路  Source: mozilla/pdf.js

Link to PDF file (or attach file here):
Untitled.pdf

Configuration:

  • Web browser and its version:Chrome Version 51.0.2704.103 (64-bit)
  • Operating system and its version: Fedora 20
  • PDF.js version: 1.5.309
  • Is an extension: npm package : pdfjs-dist

What is the expected behavior?
Get the total size of the pdf when loading it in order to make a Loading Bar

What went wrong?
When I am loading a pdf, I receive a total pdf size: "undefined" while it should display "11405" from the beginning. (You can notice that it display the right pdf size when the loading is finished)

onProgress: function ChunkedStreamManager_onProgress(args) {
---------------- : bytesLoaded : 8234
---------------- : data.total : 0
---------------- : this._contentLength : undefined

fullRequest.onProgress = function (evt) {
---------------- evt : Object {loaded: 8234, total: undefined}
---------------- : Loaded : 8234
---------------- : total : undefined
progress : Object {loaded: 8234, total: undefined}

onProgress: function ChunkedStreamManager_onProgress(args) {
---------------- : bytesLoaded : 11405
---------------- : data.total : 0
---------------- : this._contentLength : undefined

fullRequest.onProgress = function (evt) {
---------------- : evt : Object {loaded: 11405, total: undefined}
---------------- : Loaded : 11405
---------------- : total : undefined
progress : Object {loaded: 11405, total: undefined}

fvar readPromise = new Promise(function (resolve, reject) {
---------------- : Loaded : 11405
---------------- : total : 11405
progress : Object {loaded: 11405, total: 11405}

I believe it comes from my server setup since I don't have this error when serving this pdf with : http-server But in order to fully understand where the problem comes from, I need to understand the data-flow. Could you explain how the onProgress method works when we call getDocument, how and when the onProgress parameter are set (loaded and total) ? I didn't see any precise documentation on that point.

Thanks

a.d

1-other

Most helpful comment

When I am loading a pdf, I receive a total pdf size: "undefined" while it should display "11405" from the beginning.

HTTP protocol might not specify total length of the content. Notice even if Content-Length header is specified it might be wrong or specify lengths of the compressed content. If PDF.js not sure or does not know about lengths of PDF, the total is undefined. Closing as answered.

All 2 comments

Same here, file size keeps unknown until fetched.

When I am loading a pdf, I receive a total pdf size: "undefined" while it should display "11405" from the beginning.

HTTP protocol might not specify total length of the content. Notice even if Content-Length header is specified it might be wrong or specify lengths of the compressed content. If PDF.js not sure or does not know about lengths of PDF, the total is undefined. Closing as answered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SehyunPark picture SehyunPark  路  3Comments

timvandermeij picture timvandermeij  路  4Comments

sujit-baniya picture sujit-baniya  路  3Comments

AlexP3 picture AlexP3  路  3Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments