我正在尝试将 html 页面转换为 pdf,我在上传的 jpg 动态添加的画布元素前面有一个透明的 png,当我运行脚本时,它会渲染 pdf 但只渲染 jpg 图像。我已经尝试了多次迭代,也尝试了不同的渲染库,如 html2canvas 等,有人能解释一下吗,因为我不知所措??
.proof_images {
max-width:960px;
height:679px;
z-index:1;
}
.proof {
position:relative;
margin:0;
padding:0;
width:100%;
height:100%;
z-index:2;
}
<div id="print_proof" class="print_proof">
<div class="proof">
<img id="image_proof_background" class="proof_images" src="https://www.eimedia.com.au/wp-content/uploads/explainer.jpg" style="margin-bottom:20px; opacity:1;">
</div>
</div>
$("#generate").click(function() {
var element = document.getElementById('print_proof');
var opt = {
margin: 1,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'A4', orientation: 'portrait' }
};
html2pdf().set(opt).from(element).save();
});
我认为你可以使用 wkhtmltopdf 命令行工具
你能解决这个问题吗?由于通过 URL 提供的图像不会在 PDF 中呈现给我,而另一方面,我下载的图像则不会呈现给我。