Search code examples
yiiyii-extensions

Have problems in inserting stylesheet in mpdf?


$htmloutput .= $this->renderPartial('sitepdf',array(
                        'model'=>$model),true,true);
                        'sitemodel'=>$sitemodel,
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
                      $mPDF1->WriteHTML($htmloutput);
    $stylesheet = file_get_contents(Yii::getPathOfAlias('webroot.css').'/form.css');
    $mPDF1->WriteHTML($stylesheet, 1);
    $mPDF1->Output();

When I created pdf using this code, I am getting error message.

preg_replace() [<a href='function.preg-replace'>function.preg-replace</a>]: Compilation failed: regular expression is too large at offset 39815 

I tried to enter the path manually like "D:/xampp/......." even thats not working

But if I comment the style sheet, I can get the pdf without the styles I implement in it.

But I want to include the stylesheet


Solution

  • I just inserted the style sheet inside the 'sitepdf' and its working now. like

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />
    

    now its working but still my prob is, still it occupies plenty of space, I need the pdf to be displayed in less memory.(without the image) I am getting little less than 1 MB. Is there any way to reduce the PDF size further?