我需要在pdfmake生成的报告头中添加一个图像。但是,在遵循文档时,即使将图像转换为base64,我也无法进行此插入。请提出另一种解决办法
所做的工作:
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
function epiPDF(epis){
pdfMake.vfs = pdfFonts.pdfMake.vfs;
const header = [
{
text: 'Description equipament',
bold: true,
fontFamily: 'Roboto',
decoration: 'underline',
margin: [0, 20, 0, 0],
alignment: 'center',
image: 'data:image/jpeg;base64,/9j/END_DATAURL_BASE64'
}
];
function Rodape(currentPage, pageCounf){
return [
{
text: currentPage + ' / ' + pageCounf,
alignment: 'right',
fontSize: 9,
margin: [0, 10, 20, 0]
}
]
}
const docDefinitios = {
pageSize: 'A4',
pageMargins: [10, 50, 10, 40],
header: [header],
content: [infor, rec, details],
footer: [Rodape]
}
pdfMake.createPdf(docDefinitios).download();
}
export default epiPDF;
测试base64代码正确时
发布于 2022-06-13 12:04:53
请指出浏览器的错误是什么?
此外,我建议您再次尝试使用在base64中指定的[医]pdfmake操场编码的映像。
发布于 2022-06-24 06:51:07
您的代码应该如下所示:
const getHeader = (currPage, totalPage) => [
{
text: 'Description equipament',
bold: true,
fontFamily: 'Roboto',
decoration: 'underline',
margin: [0, 20, 0, 0],
alignment: 'center',
},
{
image: 'data:image...YOUR IMAGE',
margin: [0, 20, 0, 0],
alignment: 'center',
}
]
const docDefinitions = {
pageSize: 'A4',
pageMargins: [10, 50, 10, 40],
header: getHeader,
content: [infor, rec, details],
footer: Rodape
}
干杯
https://stackoverflow.com/questions/72481583
复制相似问题