通过pdf.js获取上传的pdf文件的页数方法
通过pdf.js获取上传的pdf文件的页数方法:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <input type="file" onchange="handleFileUpload(this.files)"> <script type="text/javascript" src="./assets/js/jquery.min.js"></script> <script type="text/javascript" src="./assets/js/pdf.js"></script> <script> async function handleFileUpload(files) { const file = files[0]; const pdfReader = PDFJS.getDocument({ url: URL.createObjectURL(file) }); try { const pdfDoc = await pdfReader.promise; const numPages = pdfDoc.numPages; console.log('页数:', numPages); // return numPages; } catch (error) { console.error('出错了:', error); // return 'err'; } } </script> </body> </html>
pdf.js 文件下载:QQ邮箱:309678100 标题:pdf.js获取pdf文件数