仅使用没有第三方查看器的PDF.js库,您可以使用promises获取这样的元数据.
PDFJS.getDocument(url).then(function (pdfDoc_) {
pdfDoc = pdfDoc_;
pdfDoc.getMetadata().then(function(stuff) {
console.log(stuff); // Metadata object here
}).catch(function(err) {
console.log('Error getting meta data');
console.log(err);
});
// Render the first page or whatever here
// More code . . .
}).catch(function(err) {
console.log('Error getting PDF from ' + url);
console.log(err);
});
在将pdfDoc对象转储到控制台并查看其功能和属性后,我发现了这一点.我在原型中找到了这个方法,并决定试一试.瞧,看起来有效!