我正在使用this将html转换为PDF。但我不能在标题中添加图像。这是我的代码:
nodejs:
const options = {
"format": "A4",
"base": req.protocol + '://' + req.get('host') ,
};
pdf.create(fs.readFileSync(outHtml, 'utf8'), options).toFile(outPdf, function (err) {
...
})
HTML:
<div id="pageHeader-first">
<img src="img_path">
</div>
<div id="pageHeader"></div>
我哪里错了?请帮帮我
修改 我尝试了这段代码,但仍无法正常工作:
var assetPath = path.join(__dirname,'../public/')
assetPath = assetPath.replace(new RegExp(/\\/g),'/');
const options = {
"format": "A4",
base: "file://"+assetPath,
header:{
height:"33mm"
}
};
html:<img src="images/logo.jpg" style="width:100%" alt=""/>
答案 0 :(得分:0)
请尝试:
<img src="file:///C:/full_path_to_your_image/images/logo.jpg" style="width:100%" alt=""/>