我试图弄清楚如何使用jsPDF .html()
方法调整HTML元素的大小。
我尝试使用下面的代码,但width
选项似乎没有对输出进行任何更改。
我只是假设width
是.html()
的一个选项,不幸的是,截至目前,没有这种方法的文档,人们应该猜测它from the code。
此外,在我看来它应该从html2canvas options选择,这就是为什么我尝试与width
。
无论如何,代码:
var legend = document.getElementById("my-table");
var pdf = new jsPDF(orientation, undefined, format);
pdf.html(legend, {
width: 200,
callback: function () {
window.open(pdf.output('bloburl'));
}
});
#我的表
<table>
<tr>
<td><img src="image1.jpeg"></td>
</tr>
<tr>
<td><img src="image2.jpeg"></td>
</tr>
...
</table>
将选项传递给html2canvas:
pdf.html(legend, {
html2canvas: {
// insert html2canvas options here, e.g.
width: 200
},
callback: function () {
// ...
}
});
对我来说,选项scale
适用于调整大小。您可以检索默认页面尺寸listed in the source以计算所需的缩放系数。
我不确切知道jspdf是什么,但似乎你错过了拼写
var legend = document.getElementsById("my-table");
这里。
var legend = document.getElementById("my-table");
也许,您可以通过css或style属性调整这些表的大小。
<table style="width:200;">
<tr>
<td><img src="image1.jpeg"></td>
</tr>
<tr>
<td><img src="image2.jpeg"></td>
</tr>
...
</table>
用css
#my-table {
width:200;
}