英文:
base64 image is broken when trying to render image in headertemplate puppeteer
问题
我想使用puppeteer/PDFOptions创建一个PDF。它包含在_headerTemplate_中的base64编码图像:
await page.pdf({
displayHeaderFooter: true,
printBackground: true,
headerTemplate:
'<img class="header-logo" src="data:image/png;base64,${headerimgtry}" style="height:100px; width:100px">',
footerTemplate: '<h1">Footer</h1>',
margin: "30px",
format: "A4",
path: "output.pdf",
});
但是,它只显示一个占位符而不是图像:
如何才能正确显示图像在PDF中?
英文:
I want to create a pdf using puppeteer/PDFOptions . It contains a base64 encoded image inside the headerTemplate:
await page.pdf({
displayHeaderFooter: true,
printBackground: true,
headerTemplate:
'<img class="header-logo" src="data:image/png;base64,${headerimgtry}" style="height:100px; width:100px">',
footerTemplate: '<h1">Footer</h1>',
margin: "30px",
format: "A4",
path: "output.pdf",
});
But instead of the image it only shows a placeholder:
How can I correctly display the image in the pdf?
2: https://i.stack.imgur.com/oBs0g.png "What it looks like, with a placeholder intead of the image"
3: https://i.stack.imgur.com/Ss50N.png "the code snippet"
答案1
得分: 1
使用不同的模板引擎,最近遇到了这个问题。将img/png
中的正斜杠转义为img//png
可以解决它。
英文:
I'm using a different templating engine and recently came across this issue. Escaping img/png
with a forward-slash to img//png
fixed it for me.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论