我想使用jsPDF设置PDF中显示的图像的默认缩放级别。 我试图将其设置为75%或“实际大小”。 但它没有得到确定。
我还使用了resizeImg()
但是没有设置缩放级别。
这是HTML:
<span class="col-sm-3 padding0">
<button id="downloadModel" class="btn btn-md btn-default"
style="height:100px;width: 210px"
ng-click="downloadWorkModel()">
Download Work Model
</button>
</span>
CODE:
$scope.downloadWorkModel= function(){
var image = new Image();
var width, height;
image.onload = function() {
width= this.width;
height= this.height;
width = width*4;
document.body.appendChild(this);
image = resizeImg(this, width, height);
console.log("image width: " + width);
console.log("image height: " +height);
var pdf = new jsPDF("l", "mm", [image.width, image.height]);
pdf.addImage(this, 'png', 0, 0);
pdf.save('workModel.pdf');
};
function resizeImg (image, origW, origH)
{
var resize = 100; // resize amount in percentage
//var mouseX = event.x;
//var mouseY = event.y;
var newH = origH * (resize / 100);
var newW = origW * (resize / 100);
// Set the new width and height
image.style.height = newH;
image.style.width = newW;
var c = image.parentNode;
// Work out the new center
c.scrollLeft = ((resize / 100)) - (newW / 2) / 2;
c.scrollTop = ((resize / 100)) - (newH / 2) / 2;
return image;
}