【问题标题】:HTML2PDF page sizeHTML2PDF 页面大小
【发布时间】:2013-08-27 14:08:35
【问题描述】:

我正在使用 PHP 和 HTML2PDF 库来生成 pdf 文件。但我想要做的是生成一个 pdf 文件,其中 pageSize(宽度/高度)作为 html 内容大小。我怎样才能做到这一点?

我的html内容是:

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

图片类的css是:

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

而我的 PHP 代码是:

$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));

【问题讨论】:

标签: php html2pdf


【解决方案1】:

这里是这个问题的解决方案:

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

宽度和高度应以 MM 为单位。如果您使用英寸将其转换为 MM。

公式:

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

不要四舍五入。使用精确的转换,即使它有小数点。

希望这个答案能解决你的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-28
    • 2010-10-10
    相关资源
    最近更新 更多