直接打开浏览器控制台,输入以下脚本:
function downloadPages(from, to) { for (i = from; i <= to; i++) { const pageCanvas = document.getElementById('page_' + i); if (pageCanvas === null) { break; } const pageNo = parseInt(String(i)); setTimeout(() => { console.log("==pageNo==>>", pageNo); ((num) => { console.log("开始打印第" + num + "页"); pageCanvas.toBlob( blob => { const anchor = document.createElement('a'); anchor.download = 'page_' + num + '.png'; anchor.href = URL.createObjectURL(blob); anchor.click(); URL.revokeObjectURL(anchor.href); } ); })(pageNo); }, 500 * pageNo); } }
downloadPages(page_from, page_to);
例如打印第3~5页即输入downloadPages(3, 5);
- 图片会由浏览器直接下载,可能会提示是否允许连续下载多个文件,同意即可
- 需要注意:❗要提前浏览全部文档,缓慢滚动到页面底部,等待浏览器加载图片成功,否则将保存为纯黑无内容的图片
- 后续将图片文件转存为pdf文档即可