0

我已经设法在 Yii 中使用 pdfable 创建了 pdf 文件。pdf 文档的问题在于它包含主菜单作为它不应该的列表项。这是从哪里来的,我该如何阻止它?

控制器

$asaarea = Yii::app()->db->createCommand("SELECT distinct(asaarea) FROM `hdb`.`lookupcountry`")->queryAll();        

        $results = array();
        foreach ($asaarea as $key => $value) {
            $results[$value['asaarea']] = Yii::app()->db->createCommand("SELECT
                StartDATE,
                PROJECT,
                PROJCODE,
                PROJID,
                ActualEndDate,
                OFFICE,
                PERCENT,
                PERCENTPlanned,
                KM,
                KMPlanned,
                COUNTRY,
                AREA,
                PROJINFO
                FROM view_webprojectreport where asaarea = '" . $value['asaarea'] . "'")->queryAll();
        }


        $pdf = $this->createPdf();
        $pdf->setOptions(array('orientation'=>'Landscape',
                'margin-top'    => 5,
                'margin-right'  => 10,
                'margin-bottom' => 5,
                'margin-left'   => 10,
                )
            );
        $pdf->renderPage('print',array('results'=>$results));

        $pdf->send('ProjectReport_'.date('M-Y').'.pdf');

打印.php

<head>
<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;
}
thead{
    font-size:11px;
     font-weight: normal;
}

</style>
</head>
<!-- <body onload="window.print();window.close();">-->
<body>
<h1 class="grey center">Project Report</h1>
<table>
<?php 
$count = 0;
$class= null;
foreach($results as $key=>$data) {
?>

<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>


<?php }
?>
</table>
</body>

在此处输入图像描述

4

1 回答 1

1

你没有发布这个,所以这只是一个猜测,但它可能是你布局文件中的菜单。

Pdfable 将每个页面呈现为一个普通的 Yii 页面——它不像renderPartial(). 因此,也许您应该为 PDF 创建一个特定的布局并将其配置为布局文件。例如,您可以创建views/layouts/pdf.php

<?php
// In the simplest case you only output $content here. But 
// you could also add a nice header to all your PDFs.
echo $content;

然后,您可以在您print.php的顶部添加此行。

<?php $this->layout = 'pdf'; ?>
于 2013-06-06T17:32:05.917 回答