我正在尝试将HTML页面另存为PDF
domtoimage.toPng(document.getElementById('PrintForm')).then(function(blob){var pdf = new jsPDF('p','pt',[$('#PrintForm')。width(),$('#PrintForm')。height()]); pdf.addImage(blob, 'PNG', 0, 0, $('#PrintForm').width(), $('#PrintForm').height());
pdf.save("test.pdf");
that.options.api.optionsChanged();
});</pre>
尝试一下...
var obj = $(".yourclassname")[0]
var srcwidth = obj.scrollWidth;
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.html(obj, {
html2canvas: {
scale: 600 / srcwidth
//600 is the width of a4 page. 'a4': [595.28, 841.89]
},
callback: function () {
window.open(pdf.output('bloburl'));
}
});
您的类名是页面中的对象(或#yourobjectid)。 srcwidth是宽度计算,因此您的html适合页面的宽度。您可能需要在html中添加一些填充以适合pdf(我在div中添加了20px)。您应该使用jsPdf的1.5.3版才能使以上功能正常工作。希望这会有所帮助(对我来说确实有用)。您还应该使用最新版本的html2canvas 1.0.0-rc.5