1

I'm using yii2 and installed two extension : mpdf , and yii2-barcode-generator-8-types. Both of them were installed and configured properly and working well. But what I can't do is to load barcode into pdf.

Here is my code : Controller :

 public function actionPdf()
 {
        $pdf = Yii::$app->pdf;
        $pdf->content = $this->renderPartial('_pdf');
        echo  $this->renderPartial('_pdf');exit;
        return $pdf->render();     
 }

View :

<div id="showBarcode"></div>
<?php  

use barcode\barcode\BarcodeGenerator as BarcodeGenerator;
 $optionsArray = array(
'elementId'=> 'showBarcode', 
'value'=> '12345678', 
'type'=>'code128',     
);
echo BarcodeGenerator::widget($optionsArray);
?>

And it show something like this enter image description here

but If I try to delete all code inside actionPdf() and just write

 return $this->render("_pdf");

it show like this:

enter image description here

Please help!!!

Chhorn Soro
  • 3,061
  • 8
  • 27
  • 43
  • I think you can't use them together, because yii2-barcode-generator-8-types uses jQuery to generate the barcode, and you can't use jQuery or any kind of javascript on a PDF or from server side. – marche Sep 12 '15 at 17:24

1 Answers1

1

I think your controller should be this

public function actionPdf()
{
    $pdf = Yii::$app->pdf;
    $pdf->content = $this->renderPartial('_pdf');
    return $pdf->render();     
}

The row with echo $this->renderPartial('_pdf');exit; don't must be used because it prevents the program to invoke correctly the render of the pdf page. If you use this instruction you displays only the render of "html like code" page like you see in result you posted moreover immediately after this instruction you exit form action without invoking the $pdf->render.

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107