douxueke5653 2015-09-03 12:35
浏览 290

如何使用JsBarcode.js生成条形码并使用Yii framework 2.0中的Kartik mPDF将其打印在PDF文件上

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;?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog