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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向