繁体   English   中英

如何使用puppeteer.js读取pdf文件并显示在html中?

[英]How to read the pdf file using puppeteer.js and display in html?

我希望你安全。

我正在制作一个在网站上执行一些抓取的脚本。 现在的问题是,我有一个网站有 pdf。所以我无法使用puppeteerNode.js读取 pdf 文件。

我能够从其他链接阅读其他文本。

我试过的

const puppeteer = require('puppeteer')

async function printPDF() {
   const browser = await puppeteer.launch({ headless: true });
   const page = await browser.newPage();
   await page.goto('https://blog.risingstack.com', {waitUntil: 'networkidle0'});
   const pdf = await page.pdf({ format: 'A4' });

   await browser.close();
   return pdf
})

它可以将文本添加到 pdf,但我需要 pdf 才能发短信。

有人可以帮我弄这个吗?

有一个名为“pdfreader”的 npm 模块。 你可以检查一下。

仅供参考,这在 Playwright 中是可能的,方法是使用 Firefox 并导航到 PDF 文件,该文件将使用 PDF.js 打开。 但是,最新版本的 Playwright 破坏了此功能:

https://github.com/microsoft/playwright/issues/13157

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM