我正在使用PHP和HTML2PDF lib生成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));
1 回答
以下是此问题的解决方案:
宽度和高度应为MM . 如果您使用英寸将其转换为MM .
式:
不要四舍五入 . 即使它有一个小数点,也使用精确的转换 .
希望这个答案能解决你的问题 .