如何使用jsPDF将图像设置为适合页面宽度? [英] How to set image to fit width of the page using jsPDF?

查看:912
本文介绍了如何使用jsPDF将图像设置为适合页面宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法解决这个问题? 我试图将宽度和高度设置为毫米.如何将其设置为全角?

Is there any way to solve this? I tried to set width and height in mm. How can I set it to full-width?

推荐答案

您可以像下面那样获取PDF文档的宽度和高度,

You can get the width and height of PDF document like below,

var doc = new jsPDF("p", "mm", "a4");

var width = doc.internal.pageSize.getWidth();
var height = doc.internal.pageSize.getHeight();

然后,您可以为图像使用此宽度和高度以适合整个PDF文档.

Then you can use this width and height for your image to fit the entire PDF document.

var imgData = 'data:image/jpeg;base64,/9j/4AAQSkZJ......';

doc.addImage(imgData, 'JPEG', 0, 0, width, height);

确保图像具有与PDF文档相同的尺寸(分辨率).否则,它将看起来变形(拉伸).

Make sure that your image has the same size (resolution) of the PDF document. Otherwise it will look distorted (stretched).

如果要将px转换为mm,请使用此链接 http://www. endmemo.com/sconvert/millimeterpixel.php

If you want convert px to mm use this link http://www.endmemo.com/sconvert/millimeterpixel.php

这篇关于如何使用jsPDF将图像设置为适合页面宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆