pdfpdf.jspdfjs-dist

PDFJS: Get some unnecessary chunks with range request and make first page slow


Configuration:

  1. I use the range request to render pdf
  2. I get more chunks with this line of code await this.pdfManager.requestRange(ex.begin, ex.end);;
  3. These chunks are unnecessary when rendering first page;
  4. The program also seems to run fine when I comment this line of code, and I can get less chunks to make the first page faster;
  5. So what does this part of the code do?
  6. Is it possible not to execute it or not to use await?
// src/core/xref.js

async fetchAsync(ref, suppressEncryption) {
    try {
      return this.fetch(ref, suppressEncryption);
    } catch (ex) {
      if (!(ex instanceof MissingDataException)) {
        throw ex;
      }
      await this.pdfManager.requestRange(ex.begin, ex.end);
      return this.fetchAsync(ref, suppressEncryption);
    }
  }

I can get less chunks when I comment this line of code and the program also seems to run fine

image

If I do nothing,the range request in network like this

image


Solution

  • In v2.12.313, PDFJS will check that the last page can be sucessfully loaded during document initialization, to ensure that numPages is correct, and fallback to walking the entire /Pages-tree. #14570