I have installed Kartik mPDF
extension within Yii framework 2.0
. Below is the code snippet within my controller that generates PDF file and send it to the browser.
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $this->renderPartial('print-barcode'),
'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline' => '.kv-heading-1{font-size:18px}',
'options' => ['title' => 'My PDF file'],
'methods' => [
'SetHeader'=>['My header'],
'SetFooter'=>['{PAGENO}'],
]
]);
return $pdf->render();
I have two JS files (JsBarcode.js
and CODE128.js
) which can be found here https://github.com/lindell/JsBarcode
To generate barcode I need to include these JS files and my custom JavaScript code. In my view, I normally include those files as follows (my print-barcode.php
).
<?php
$this->registerJsFile(Yii::$app->urlManager->baseUrl . '/js/JsBarcode.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
$this->registerJsFile(Yii::$app->urlManager->baseUrl . '/js/Code128.js', ['depends' => [\yii\web\JqueryAsset::className()]]);
$jsGenerateBarcode = 'My custom Javascript code goes here ...';
$this->registerJs($jsGenerateBarcode, $this::POS_END);
?>
All the included JavaScript code does not have any effect at all, since it is a PDF file and not a webpage. How can I print the barcode generated by JsBarcode.js
and by CODE128.js
and pass it on the PDF file which is generated by kartik\mpdf\Pdf;
?