question 1:
do a function to generate PDF. Html is read locally without network connection.
there is a test.jpg file in the root directory. Now I write the PDF generated by the relative path directly without pictures.
could you tell me how to write the picture so that the picture can be loaded?
const puppeteer = require("puppeteer");
const fs = require("fs");
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
//
// try {
// await page.goto("http://www.baidu.cn");
// } catch (error) {
// console.log(""+ error)
// }
await page.setContent(`<img src="/images/test.jpg" alt="">
<div>dddddddd</div>`);
try{
await page.pdf({
displayHeaderFooter: true,
path: "demo.pdf",
format: "A3",
margin:
{
top: "100px",
bottom: "200px",
right: "30px",
left: "30px",
}
});
}catch(err){
console.log("error:" + err)
}
await page.once("load", () => console.log(""));
await browser.close();
})();
question 2: how do I add the number of pages when setting the header by the page.pdf method in
puppeteer?
the screenshot is an official document, but how can I write it to get the value of pageNumber?