I am trying to create a PDF file using html2pdf. I have followed this guide. I can create it in html fine and everything is in printable area however the created PDF does not display same results. the table width are not kept. Data is cut off at end of page on right side.
In controller
$html2pdf = Yii::app()->ePdf->HTML2PDF('L',"A4","en", array(10, 10, 10, 10));
$html2pdf->WriteHTML($print);
$html2pdf->Output();
page to be created
<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>
Using pdfable I get following error:
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
after updating to $this->renderPdf('print',array('results'=>$results));
i get new error
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)
via mpdf
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 258180 bytes) in /opt/paradox/protected/vendors/MPDF56/mpdf.php on line 10125, referer: http://portal-test/paradox/index.php?r=ViewWebprojectreport/admin
I pasted the styling in the variable $stylesheet