Hy guys,
如何使用Zend_PDF显示条形码?
这是我的代码:
$config = new Zend_Config(array(
'barcode' => 'code39',
'barcodeParams' => array('text' => '11020109'),
'renderer' => 'image',
'rendererParams' => array('imageType' => 'gif'),
));
$renderer = Zend_Barcode::factory($config)->render();
现在如何将其渲染到我的PDF格式? 我尝试没有成功:
$barcode = Zend_Pdf_Image::imageWithPath($renderer);
$page->drawImage($barcode, 10, 510, 290, 550);
感谢
答案 0 :(得分:2)
以下内容应该让您前进,您需要更改3件事,渲染器,将条形码渲染为pdf的方法以及一些不明原因,您必须在Zend_Barcode中包含字体,否则您将获得错误
$pdf = new Zend_Pdf();
// Your font (path might differ)
Zend_Barcode::setBarcodeFont(APPLICATION_PATH . '\..\data\resources\fonts\arial.ttf');
$config = new Zend_Config(
array(
'barcode' => 'code39',
'barcodeParams' => array('text' => '11020109'),
'renderer' => 'pdf', // here is your new renderer
'rendererParams' => array(), // you can define position offset here
)
);
$pdfWithBarcode = Zend_Barcode::factory($config)->setResource($pdf)->draw(); // your new barcode renderer is defined here, from now on to add things to your pdf you need to use the new variable ($pdfWithBarcode)
// Save your pdf (path might differ)
$pdfWithBarcode->save(APPLICATION_PATH . '\..\data\testBarcode.pdf');