我正在使用pdf.js在页面中显示pdf的缩略图。那里有多个pdf。如果pdf大小太大(例如200mb甚至更大),则将发生大量下载,从用户的角度来看,这根本不可行。我只想获取文档的第一页,以提高性能。我当前的代码:
if(filename.split('.').pop() == 'pdf'){
var pdfjsLib = window['pdfjs-dist/build/pdf'];
pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.943/pdf.worker.min.js';
var loadingTask = pdfjsLib.getDocument({url:images,disableAutoFetch: true, disableStream: true});
loadingTask.promise.then(function (pdf) {
console.log('PDF loaded');
pdf.getPage(1).then(function getPageHelloWorld(page) {
var scale = 1.5;
var viewport = page.getViewport(scale);
console.log('page', viewport);
//
// Prepare canvas using PDF page dimensions
//
var canvas = document.getElementById(filename);
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;
//
// Render PDF page into canvas context
//
page.render({canvasContext: context, viewport: viewport});
});
});
}
disableAutoFetch无法正常工作,有什么想法吗?