how to change height and width manually of pdf by using html2pdf in php

安稳与你 提交于 2019-12-12 02:23:05

问题


i am using html2pdf to convert html to pdf... actually i have a large size of html container like 12x12in (inches). and i have used A4 size for the first time then my html content not showing completely till as per the size (12x12 in) then i have look into your site and i found all paper size here.. thanks for that important info... but now, when i have used A3 size i have found, my all html content inside the pdf file....but there are so much space at the bottom of my contents in pdf... So i want to know... IS there any way to reduce this space from the pdf or any other way to convert html to pdf with manually defined page height and width...

Thanks in Advance.


回答1:


The constructor of the HTML2PDF class says, that the $format parameter is the same as in the tcpdf class. The constructor of the tcpdf class says about the $format parameter:

@param mixed $format The format used for pages. It can be either one of the following values (case insensitive) or a custom format in the form of a two-element array containing the width and the height (expressed in the unit given by unit) ...

With a little bit of calculation, this make it possible to set the page size to 12'' x 12''. The default unit is millimeters.




回答2:


Here is the solution for this problem:

$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. If your using inches convert it to MM.

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

Don't round it off. Used the exact conversion even if it has a decimal point.

Hope this answer will solve your problem.



来源:https://stackoverflow.com/questions/15546019/how-to-change-height-and-width-manually-of-pdf-by-using-html2pdf-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!