Yii Pdf Extension: Blank Page When Calling Action Through Link

Hi all, Yii newbie here!

I have a question about the following yii extension: http://www.yiiframework.com/extension/pdf/

I want to use the mpdf external library. According to the installation instructions I have to include the mpdf initialization code in the actionIndex.

This works fine, and a pdf is generated. However, I want to include the initialization code in a separate action in my SiteController and call this action from a view file through a link.

This is what I have so far, but I only get a blank page.

SiteController.php:




...

    public function actionGeneratePdf()

    {

        # mPDF

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

 

        # You can easily override default constructor's params

        # $mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');

 

        # render (full page)

        $mPDF1->WriteHTML($this->render('index', array(), true));

 

        # Load a stylesheet

        $stylesheet = file_get_contents(Yii::getPathOfAlias('webroot.css') . '/main.css');

        $mPDF1->WriteHTML($stylesheet, 1);

 

        # renderPartial (only 'view' of current controller)

        # $mPDF1->WriteHTML($this->renderPartial('index', array(), true));

 

        # Renders image

        # $mPDF1->WriteHTML(CHtml::image(Yii::getPathOfAlias('webroot.css') . '/bg.gif' ));

 

        # Outputs ready PDF

        $mPDF1->Output();

    }

...



View file:




<?php echo CHtml::link('Generate PDF',array('site/GeneratePdf')); ?>



Anyone please :unsure:

instead of loading style sheet like this

Load a stylesheet

$stylesheet = file_get_contents(Yii::getPathOfAlias(‘webroot.css’) . ‘/main.css’);

$mPDF1->WriteHTML($stylesheet, 1);

Try to load in the view file "index"

Rendering of images also should be moved to the view file "index"

Thanks for you reply Kumar, but I dont really understand what you mean.

I already load my main.css in my index view, so could you show me in more detail what you mean…

Hi,

for test, can you change this LOC

$stylesheet = file_get_contents(Yii::getPathOfAlias(‘webroot.css’) . ‘/main.css’);

to

$stylesheet = "<style>your css code or main.css content</style>";

Still blank page after copying the css code of print.css :(