Export Gridview To Pdf

My code in controller is

public function actionPdf()

{

// $this->layout = ‘pdf’;

$model=new VehicleLogbookTbl(‘search’);

if(isset($_GET[‘VehicleLogbookTbl’]))

$model->attributes=$_GET[‘VehicleLogbookTbl’]; /* to execute the filters (if is the case) */

$dataProvider      = $model->search();


 $dataProvider->pagination = false; 





$mPDF1 = Yii::app()->ePdf->mpdf();





//$mPDF1->WriteHTML($this->renderPartial('_pdf_header', array(), true));





$mPDF1->WriteHTML($this->renderPartial('admin', array($dataProvider->data), true));

// $mPDF1->WriteHTML($this->renderPartial(’_pdf_footer’, array(), true));

$mPDF1->Output();  


}

And I am calling the function from admin

echo CHtml::link(‘Generate PDF’, array(‘VehicleLogbookTbl/Pdf’));

The output is

Instead of disabling pagination you should loop over all pages to avoid creating a model for each row from dataProvider. There is a special class to help you with that, called DataProviderIterator. Check out the docs, there’s an example.

I had a similar problem when exporting large amounts of data to CSV through a grid. I developed my own exporter extension that outputs data while reading them from the database, row by row. It performs one database query and doesn’t generate much load on the server.

You could override the CsvView class in my extension and make it write to the mPdf instance. Check out JsonView for an example how it’s done.