我使用PDFJS来显示PDF。通过viewer.js的这个片段(来自PDFJS包的文件)正确捕获了大多数错误:
PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded).then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
self.loading = false;
},
function getDocumentError(message, exception) {
但是当PDF长度为0时出错:
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);
在util.js中抛出错误的代码片段如下所示:
// 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);
}
所以我的问题是,如何在viewer.js PDFView类中正确处理PDF JS中的0文件大小PDF错误?