const puppeteer = require('puppeteer');
const docHeight = () => {
const body = document.body
const html = document.documentElement;
return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
}
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://en.wikipedia.org/wiki/JavaScript");
const height = await page.evaluate(docHeight);
await page.pdf({path: `js.pdf`, height: `${height}px`})
})();
转载自:https://stackoverflow.com/questions/70345012/puppeteer-how-to-generate-pdf-that-only-has-one-page-and-the-page-contains-all 的问题解答