It is possible yes. I do not use an extension I use a library called HTML2PDF http://www.html2pdf.fr/en I put it in my extensions folder. I created a pdf action that has this code
<?php
class Pdf extends CAction {
public function run() {
$controller = $this->getController();
\Yii::import('core.extensions.Html2Pdf.HTML2PDF');
//use the existing filters
$model_name = $controller->modelName();
$model = new $model_name('search');
$dataProvider = $model->active()->search();
//remove the pagination
$dataProvider->setPagination(false);
//get the html to transform
$content = $controller->renderPartial('pdf',array(
'dataProvider'=>$dataProvider,
'title'=>$controller->modelName() . ' - '.date('F j, Y, G:i'),
), true);
try
{
if(isset($_GET['test'])) {
echo $content;
} else {
//create the PDF
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$html2pdf->Output($controller->modelName() . '_'.date('Y-m-d').'.pdf');
}
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
}
That I can attach to any controller like this
/**
* @return array actions to be mapped to this controller
*/
public function actions(){
return array(
'csv'=>array(
'class'=>'core.components.actions.Csv',
'field_list'=>array('t.id', 't.name', 't.status'),
),
'pdf'=>array(
'class'=>'core.components.actions.Pdf',
),
);
}
. There is a view called pdf that has what I want to export as PDF. I am actually creating simple HTML (so nothing very complicated and most of the styles are inline). An example is
<page backtop="22mm" backbottom="8mm" backleft="0" backright="0">
<page_header>
<h1> <?php echo $title?></h1>
<table backleft="10mm" style="width: 700px;" align="center">
<tr>
<td style="width: 10%; border-bottom: 1px solid black;">ID</td>
<td style="width: 75%; border-bottom: 1px solid black;">Name</td>
<td style="width: 15%; border-bottom: 1px solid black;">Status</td>
</tr>
</table>
</page_header>
<page_footer>
<table style="width: 700px; border-top: 1px solid black;" align="center">
<tr>
<td style="text-align: left; width: 50%"></td>
<td style="text-align: right; width: 50%">page [[page_cu]]/[[page_nb]]</td>
</tr>
</table>
</page_footer>
<table style="width: 700px;" align="center">
<?php
foreach($dataProvider->getData() as $record) {
?> <tr>
<td style="width: 10%;"><?php echo $record->id?></td>
<td style="width: 75%;"><?php echo $record->name?></td>
<td style="width: 15%;"><?php echo ucfirst($record->status)?></td>
</tr>
<?php
}
?> </table>
</page>