How nodejs converts html to pdf

for example, how to print its contents into a pdf file through the address of a html

Mar.28,2021

this operation can be done by looking for a three-party package.

The first result of

Google has a https://www.npmjs.com/package/html-pdf, < del > but uses the dead project phantomjs as the renderer, which is not recommended. < / del >

passers-by who do not answer questions, please do not casually report other people's hand-holding parties. Everyone is a hand-holding party, but you are ashamed to be silent when you reach out your hand.


puppteer
can be installed via npm

const puppeteer = require('puppeteer');
(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://www.baidu.com');
  await page.pdf({path: 'baidu.pdf', format: 'A4'});
  await browser.close();
})();

Menu