How to handle stream should have data error in PDF JS?

I am using PDFJS to display PDF files. Most bugs are fixed with this viewer.js snippet (file from PDFJS package):

PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded).then(
      function getDocumentCallback(pdfDocument) {
        self.load(pdfDocument, scale);
        self.loading = false;


      },
      function getDocumentError(message, exception) {

      

But when the PDF has a length of 0, the error is:

Error: stream must have data
util.js (wiersz 62)

assertWellFormed@http://www.polishwords.com.pl/dev/pdfjs/src/util.js:124:5
init@http://www.polishwords.com.pl/dev/pdfjs/src/core.js:296:5
PDFDocument@http://www.polishwords.com.pl/dev/pdfjs/src/core.js:288:7
LocalPdfManager@http://www.polishwords.com.pl/dev/pdfjs/src/pdf_manager.js:75:21
onDone@http://www.polishwords.com.pl/dev/pdfjs/src/worker.js:212:24
NetworkManager_onStateChange@http://www.polishwords.com.pl/dev/pdfjs/src/network.js:190:1

util.js (wiersz 64)
Error: stream must have data


throw new Error(msg);

      

The snippet of code causing the error in util.js looks like this:

// Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception.
function error(msg) {
  // If multiple arguments were passed, pass them all to the log function.
  if (arguments.length > 1) {
    var logArguments = ['Error:'];
    logArguments.push.apply(logArguments, arguments);
    log.apply(null, logArguments);
    // Join the arguments into a single string for the lines below.
    msg = [].join.call(arguments, ' ');
  } else {
    log('Error: ' + msg);
  }
  log(backtrace());
  PDFJS.LogManager.notify('error', msg);
  throw new Error(msg);
}

      

So my question is how to properly handle PDF to PDF error in PDF JS in the viewer.js PDFView class?

+3


source to share





All Articles