我正在尝试使用cakepdf从视图生成pdf但是它没有按预期工作。请在第一次使用此插件时请耐心等待。
这是我的设置
控制器操作
$this->pdfConfig = array(
'orientation' => 'portrait',
'filename' => $report['reg_no'],
'permissions' => array(
'print','screen_readers','copy_contents'
)
);
$cakePdf = new CakePdf(); //create an instance of the cakePdf class
$cakePdf->template('pdf_view','default'); //define view to use and optional layout
$pdf = $cakePdf->output();
$pdf = $cakePdf->write(APP . 'webroot' .DS .'files'. DS . 'report.pdf');
//$this->set('tcpdf',$tcpdf);
$this->set('report',$report);
$this->render('/Pdf/pdf_view');
我的pdf_view.ctp包含以下代码:相当长
<style>
tr .title {
font-weight: bold;
padding: 5px;
width:100px;
}
tr .text {
padding-left: 10px;
}
<div>
<?php
if($report['school']['logo'] == NULL){echo $this->Html->image('/logo_small.png',array('width'=>'100px','height'=>'100px'));
}else {
echo $this->Html->image($report['school']['logo'],array('width'=>'100px','height'=>'100px'));
}
?>
<p>
<font size="5"><b><?php echo $report['school']['name']; ?></b></font><br />
<b><?php echo $report['school']['motto']; ?></b><br />
<b><?php echo $report['school']['address']; ?></b>
</p>
<p align="center"><b><font size="4">Report Card</font></b></p>
<div>
<table align="left">
<tr>
<td class="title">Admission_no</td>
<td class="text"><?php echo $report['reg_no']; ?></td>
</tr>
<tr>
<td class="title">Form</td>
<td class="text"><?php echo $report['form']; ?></td>
</tr>
<tr>
<td class="title">Position</td>
<td class="text"><?php echo $report['rank']; ?></td>
</tr>
</table>
</div>
<div>
<table align="left">
<tr>
<td class="title">Name</td>
<td class="text"><?php echo $report['name']; ?></td>
</tr>
<tr>
<td class="title">Stream</td>
<td class="text"><?php if($report['stream'] == NULL){
echo "<N/A>";
}else {
echo $report['stream'];
} ?></td>
</tr>
<tr>
<td class="title">Out Of</td>
<td class="text"><?php echo $report['outof']; ?></td>
</tr>
</table>
</div>
<br /><br />
<div style="clear:left"><hr />
<!--<table>
<thead>
<tr>
<th>Subject</th>
<th>Score</th>
<th>Grade</th>
<th>Points</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php /*foreach ($report['subjects'] as $key => $value): ?>
<tr>
<td><?php echo $key; ?></td>
<td><?php echo $value['score']; ?></td>
<td><?php echo $value['grade']; ?></td>
<td><?php echo $value['points']; ?></td>
</tr>
<?php
$totPoints += $value['points'];
endforeach; ?>
<tr>
<td>Total</td>
<td><?php echo $report['total']; ?></td>
<td><?php echo $totPoints;*/ ?></td>
</tr>
</tbody>
</table>-->
</div>
<br /><hr /><br />
<p>
<font size="4"><b>Class Teacher Remarks</b></font><br /><br />
<font size="4"><b>Principal Remarks</b></font><br /><br />
<font size="4"><b>Fees Balance</b></font><br />
<font size="4"><b>Closing Date</b></font>
<font size="4"><b>Opening Date</b></font>
</p>
问题:
1.未应用表格的内嵌样式。
2.生成的pdf中充满了关于未定义变量的通知:pdf_view.ctp中的报告(但我使用了
$this->set('report',$report)
在我的控制器动作中)
即使在dompdf_config.inc.php中设置了此图像,我的图像也不会显示在pdf中
define(&#34; DOMPDF_ENABLE_REMOTE&#34;,true);
4.关于注释掉的tbody标签..如果我取消注释,我会收到错误
Error: Call to undefined method DOMText::getAttribute()
File: /home/r2d2/web-php/sms/app/Plugin/CakePdf/Vendor/dompdf/include /cellmap.cls.php
Line: 400
问题:为什么我得到undefinde变量报告,图片没有加载,样式没有应用,#4以上 ..
答案 0 :(得分:0)
设法解决了我的所有问题。可能对另一个第一次插件用户有帮助:
1.实现你不能像pdf渲染一样传递变量,就像你在stackoverflow上的其他答案一样:这工作
$this->viewVars(array("report",$report));
2.images ::通过添加fullbase数组选项解决:
echo $this->Html->image($report['school']['logo'],array('width'=>'100px','height'=>'100px','fullBase'=>true));
3.删除了tbody标签。从文档中看出我的大多数css样式都不受支持