我正在尝试使用 html2pdf 创建 PDF 文件。我已遵循本指南。我可以在 html 中很好地创建它,并且所有内容都在可打印区域中,但是创建的 PDF 不会显示相同的结果。不保留表格宽度。数据在右侧页尾被截断。
在控制器中
$html2pdf = Yii::app()->ePdf->HTML2PDF('L',"A4","en", array(10, 10, 10, 10));
$html2pdf->WriteHTML($print);
$html2pdf->Output();
要创建的页面
<style type="text/css">
@media print{thead{display:table-header-group; margin-bottom:2px;}}
@page{margin-top:1cm;margin-left:1cm;margin-right:1cm;margin-bottom:1.5cm;}}
.odd {
background: none repeat scroll 0 0 #E5F1F4;
}
.even {
background: none repeat scroll 0 0 #F8F8F8;
}
table tbody tr:hover{
background: none repeat scroll 0 0 lightgreen;
}
table tbody tr{
font-size:10pt;
}
body
{
margin: 0mm 0mm 0mm 0mm;
}
.grey{
background: lightgrey;
}
.center{
margin: 0 auto;
text-align: center;
}
.size{
font-size:15px;
}
table{
padding-botton:30px;
}
</style>
<body onload="window.print();window.close();">
<h1 class="grey center">Project Report</h1>
<?php
$count = 0;
$class= null;
foreach($results as $key=>$data) {
?>
<table width=0>
<tr class="grey size">
<th colspan=12><?=$key ?></th>
</tr>
<thead>
<tr>
<th>Start Date</th>
<th>Name</th>
<th>Code</th>
<th>Actual End Date</th>
<th>Office</th>
<th>%</th>
<th>% Planned</th>
<th>KM</th>
<th>KM Planned</th>
<th>Country</th>
<th width="150">AREA</th>
<th>PROJ INFO</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $column=>$q) { ?>
<?php
$class = ($count % 2 === 0) ? 'odd' : 'even';
$this->renderPartial('_report',array('data'=>$q,'class'=>$class));
$count++;
}
?>
</tbody>
</table>
<?php }
?>
</body>
_report.php
<tr class=<?=$class?>>
<td><?php //$startdate =
echo CHtml::encode($data['StartDATE']);
/*$createstartdate = new DateTime($startdate);
$strip = $createstartdate->format(Yii::app()->params['companies'][Yii::app()->params['currentLocation']]['dateFormat']);
echo($strip);
$strip = null;*/
?></td>
<td><?php echo CHtml::encode($data['PROJECT']);?></td>
<td><?php echo CHtml::encode($data['PROJCODE']); echo CHtml::encode($data['PROJID']);?></td>
<td><?php //$enddate =
echo CHtml::encode($data['ActualEndDate']);
/*$createenddate = new DateTime($enddate);
$strip = $createenddate->format(Yii::app()->params['companies'][Yii::app()->params['currentLocation']]['dateFormat']);
echo($strip);
$strip = null;*/
?></td>
<td><?php echo CHtml::encode($data['OFFICE']);?></td>
<td><?php echo CHtml::encode($data['PERCENT']);?></td>
<td><?php echo CHtml::encode($data['PERCENTPlanned']);?></td>
<td><?php echo CHtml::encode($data['KM']);?></td>
<td><?php echo CHtml::encode($data['KMPlanned']);?></td>
<td><?php echo CHtml::encode($data['COUNTRY']);?></td>
<td><?php echo CHtml::encode($data['AREA']);?></td>
<td><?php echo CHtml::encode($data['PROJINFO']);?></td>
</tr>
使用 pdfable 我得到以下错误:
Stack trace:
#0 /opt/yii-1.1.12.b600af/framework/web/CController.php(783): CController->renderPartial('<style type="te...', Array, true)
#1 /opt/paradox/protected/extensions/pdfable/PdfFile.php(131): CController->render('<style type="te...', Array, true)
#2 /opt/paradox/protected/extensions/pdfable/PdfFile.php(86): PdfFile->render('<style type="te...', Array)
#3 /opt/paradox/protected/extensions/pdfable/Pdfable.php(205): PdfFile->renderPage('<style type="te...', Array, Array)
#4 [internal function]: Pdfable->renderPdf('<style type="te...')
#5 /opt/yii-1.1.12.b600af/framework/base/CComponent.php(261): call_user_func_array(Array, Array)
#6 [internal function]: CComponent->__call('renderPdf', Array)
#7 /opt/paradox/protected/controllers/ViewWebprojectreportController.php(297): ViewWebprojectreportController->renderPdf('<style type="te...')
#8 /opt/yii-1.1.12.b600af/framework/web/actions/CInlineAction.php(50): ViewWebprojectreportController->actionPrint()
#9 /opt/yii-1.1.12.b600af/framework/web/CController.php(309): CInlineAction->runWithParams(Array)
#10 /opt/yii-1.1.12.b600af/framework/web/filters/CFilterChain.php(134): CController->runAction(Object(CInlineAction))
#11 /opt/yii-1.1.12.b600af/framework/web/CController.php(292): CFilterChain->run()
#12 /opt/yii-1.1.12.b600af/framework/web/CController.php(266): CController->runActionWithFilters(Object(CInlineAction), Array)
#13 /opt/yii-1.1.12.b600af/framework/web/CWebApplication.php(283): CController->run('print')
#14 /opt/yii-1.1.12.b600af/framework/web/CWebApplication.php(142): CWebApplication->runController('ViewWebprojectr...')
#15 /opt/yii-1.1.12.b600af/framework/base/CApplication.php(162): CWebApplication->processRequest()
#16 /opt/paradox/index.php(13): CApplication->run()
#17 {main}
REQUEST_URI=/paradox/index.php?r=ViewWebprojectreport/print
HTTP_REFERER=http://portal-test/paradox/index.php?r=ViewWebprojectreport/admin
更新到$this->renderPdf('print',array('results'=>$results));
我得到新的错误后
2013/06/05 12:11:33 [error] [ext.pdfable.Pdfable] Could not create PDF for view print
in /opt/paradox/protected/extensions/pdfable/Pdfable.php (209)
in /opt/paradox/protected/controllers/ViewWebprojectreportController.php (297)
in /opt/paradox/index.php (13)
通过 mpdf
PHP 致命错误:在第 10125 行的 /opt/paradox/protected/vendors/MPDF56/mpdf.php 中,允许的内存大小为 268435456 字节已用尽(试图分配 258180 字节),参考:http://portal-test/paradox/index .php?r=ViewWebprojectreport/admin
我将样式粘贴到变量中$stylesheet