简体   繁体   English

如何使 pdf 的高度和宽度与 html 相同,同时使用 html?

[英]How to make the pdf height and width same as html while converting html to pdf using html2pdf?

Sample image示例图像

How to remove the extra space in the pdf?如何删除 pdf 中的多余空间? I'm using html2pdf.我正在使用html2pdf。

can anyone please help?有人可以帮忙吗?

Below is my sample code下面是我的示例代码

var $Obj = $("<div/>").html('<div style="height: 300; width: 400; border: 3px solid #ccc; min-height:500px"><p style="margin-top:20px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p> <p  style="margin-top:20px">Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>');
       
html2pdf($Obj[0], {
    margin: 0,
    filename: 'sample.pdf',
    html2canvas: { scale: 2 },
    jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
});

Check out the link given below and set height accordingly to A4 size查看下面给出的链接并根据 A4 尺寸设置高度

$html2pdf = new HTML2PDF('P', array($width_in_mm,$height_in_mm), 'en', true, 'UTF-8', array(0, 0, 0, 0));

Width and Height should be in MM.宽度和高度应以 MM 为单位。

$width_in_mm = $width_in_inches * 25.4; 
$height_in_mm = $height_in_inches * 25.4;

HTML2PDF page size HTML2PDF 页面大小

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM