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

2

0

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.

Derick answered 21/3, 2013 at 11:18 Comment(3)
There are many PHP scripts that use the name html2pdf. Which one are you talking about?Fou
i am using html2pdf class..Derick
here is a link of that html2pdf.fr/en/exampleDerick
F
3

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.

Fou answered 21/3, 2013 at 12:42 Comment(2)
Actually i am totally confused... should i pass the size value like 12,12 in place of A4... Please see here... $html2pdf = new HTML2PDF('P', 'A4','en', false, 'ISO-8859-15', array(0,0,0,0));Derick
OMG... Thanks a lot ... i just convert inches to mm and pass in array and its works fine.... Thank you very much... i was getting upset, but this solution solve my one problem... thank u very again...Derick
M
3

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.

Marozas answered 22/12, 2013 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.