我使用html2canvas和jspdf从html转换为pdf.
我使用的是a3格式的pdf,但内容宽度为ix 1000px.所以在1000px之后,pdf显示黑色背景.
canvas{
background: #fff !important;
background-color: #fff !important
margin: 0;
}
#cisForm {
padding: 10px;
width: 1000px;
margin: 0;
background: #fff !important;
}
cisForm是身体
window.onload = function() {
html2canvas(document.body).then(function(canvas) {
background:'#fff',
document.getElementById("cisForm").appendChild(canvas);
document.body.appendChild(canvas);
var context = canvas.getContext("2d");
context.fillStyle="#FFFFFF";
l = {
orientation: 'p',
unit: 'pt',
format: 'a3',
compress: true,
fontSize: 8,
lineHeight: 1,
autoSize: false,
printHeaders: true
};
var doc = new jsPDF(l, "", "");
doc.addImage(canvas.toDataURL("image/jpeg"),"jpeg",0,0)
window.location=doc.output("datauristring")
});
}
这段代码没用.这是从html转换为pdf.
还有一个问题.
一些有限的内容仅以pdf格式出现.有些内容没有到来.
我们需要在任何地方设置no.of页面吗?
如何从pdf中删除黑色背景