不调用其他库读取pdf文档页数
wx.chooseMessageFile({
count: 1,
type: 'file',
success(res) {
const tempFilePaths = res.tempFiles
//调用getFileSystemManager
const fs = wx.getFileSystemManager()
fs.readFile({
filePath: tempFilePaths[0].path,
encoding: 'binary',
position: 0,
success(res) {
console.log(res)
//页数计算
var count = res.data.match(/\/Type[\s]*\/Page[^s]/g).length;
console.log('Number of Pages:', count);
},
fail(res) {
console.error(res)
}
})
}
})
看懂pdf.js源码,不就完事了?