HTML2PDF Page Size

I use PHP and HTML2PDF lib to create pdf files. But I'm trying to create a pdf file with page size (width / height) as html content. How can I achieve this?

My html content:

<page format="432x240" orientation="L" backcolor="#FFFFFF" style="font: arial;"> <div class="image"> <span class="firstname">$fname</span> <span class="lastname">$lname</span> </div> 

The css class for the image:

 position: relative;width: 100%; /* for IE 6 */ background-image: url(../img/test.png);height: 240px; width: 432px;top: 50%; 

And my PHP code:

 $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 0); $html2pdf->pdf->SetDisplayMode('fullpage'); $contentTpl = $this->renderPartial('template_01', array('fname' => $firstname, 'lname' => $lastname), true); $html2pdf->writeHTML(utf8_encode($contentTpl)); 
+4
source share
1 answer

Here is a solution to 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 used inches convert it to MM.

Formula:

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

Do not round it. The exact conversion is used, even if it has a decimal point.

Hope this answer solves your problem.

+3
source

Source: https://habr.com/ru/post/1499159/


All Articles