HTML2PDF page size
Asked Answered
V

1

9

I'm using PHP & HTML2PDF lib to generate pdf files.But what I'm trying to do is to generate a pdf file with the pageSize (width/height) as html content size. How can I achieve this?

My html content is:

<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 for image class is:

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

And my PHP code is:

$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));
Venireman answered 27/8, 2013 at 14:8 Comment(1)
Please check this #15546519Neurophysiology
M
12

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.

Mair answered 27/12, 2013 at 3:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.