我使用整个document.body
创建PDF,将其转换为画布并将其传递给jsPDF
。但图像/画布太宽。我想为页面缩放它,但jsPDF
没有像素大小作为度量。
选项包括:pt
,mm
,cm
。我该如何正确调整尺寸?如果需要,我如何缩放图像?
我应该使用addImage
函数来缩放,还是使用canvas.getContect(" 2d")并绘制到新画布来缩放?
html2canvas(
document.body,
{
//When the canvas is created, our callback
onrendered: function(canvas)
{
//Create jsPDF with what measurements?
var doc = new jsPDF('p', 'pt');
/*
* Put image on page. Are these measurements
* in pts? How does that compare to pixels?
*
* Is the x/y (the 10, 10) the x and y in the image?
* Or in the page where the image is printed?
*
* Should I be using this to scale, or scale by
* using canvas.getContect( "2d" ) and drawing on
* to a new canvas?
*/
doc.addImage(canvas, 'PNG', 10, 10, 1024, 1000);
//Save
doc.save('sample-file.pdf');
}
});