首先使用mpdf創建一個pdf文件,例如viewpdf.php,並在標籤中調用條形碼功能。
鑑於文件夾中創建viewpdf.php
<?php
$code= KD12345;
include("mpdf/mpdf.php");
$html='<html>
<head>
<style>
.container{width: 1450px; padding-bottom:2px;}
body, table {
/* to centre page on screen*/
margin:0 auto;
font-size: 12px;
border-collapse: collapse;
}
</style>
</head>
<body>
<div class="container" style="padding-top:2%;">
<img class="img-responsive" style="text-align:center;" src="'. base_url().'index.php/Controller/barcode?bcd='.$code.'" alt="">
</div>
</body>
</html>';
$mpdf=new mPDF('', 'A4', 0, '', 2, 2,5, 0, 0, 0);
header("Content-type:application/pdf");
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$mpdf->Output($code.'.PDF','I');
exit;
?>
在控制器夾Controller.php這樣寫一個下面的函數來顯示viewpdf.php
public function ViewPdf()
{
$this->load->view("viewpdf.php");
}
和用於生成另一功能條形碼
public function barcode()
{
$code=$_GET['bcd'];
$this->load->library('zend');
$this->zend->load('Zend/Barcode');
$barcodeOptions = array('text' => $code);
$rendererOptions = array('imageType'=>'png');
Zend_Barcode::factory('code128', 'image', $barcodeOptions, $rendererOptions)->render();
}
嗯...什麼是問題? – VirCom
我想將其更改爲pdf如何做到這一點 –
$ pdf = new Zend_Barcode_Renderer_Pdf(); \t \t $ barcodeOptions =陣列( \t \t \t '文本'=> '11111', \t \t); \t \t $ rendererOptions =陣列( \t \t \t 'topOffset'=> 50, \t \t \t '左偏移'=> 50, \t \t); \t \t Zend_Barcode ::工廠( 'CODE39', 'PDF', \t \t \t $ barcodeOptions,$ rendererOptions) - > setResource($ PDF) - >平局(); –