[英]How To access ZF2 Barcode in view
I would like to render multiple Zend Framework 2 barcodes on a page. 我想在页面上呈现多个Zend Framework 2条码。
I have been following this example (although it is for ZF1) Zend Framework Render Barcodes Into PDF Pages 我一直在关注此示例(尽管它适用于ZF1), Zend Framework会将条形码渲染为PDF页面
I am currently using DOMPDFModule
to create a pdf. 我目前正在使用DOMPDFModule
创建pdf。
How do I display the barcode using ZF2? 如何使用ZF2显示条形码? How can I render them in the view? 如何在视图中渲染它们?
// Only the text to draw is required
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
// No required options
$rendererOptions = array(
'imageType' => 'gif'
);
// Draw the barcode in a new image,
$imageResource = Barcode::factory(
'code39', 'image', $barcodeOptions, $rendererOptions
)->draw();
When I var_dump $imageResource
I get: 当我var_dump $imageResource
我得到:
"resource(459) of type (gd)" “类型(gd)的资源(459)”
When I use imagegd()
I get a bunch of symbols. 当我使用imagegd()
,会得到很多符号。
Not sure I am going down the best path. 不知道我要走最好的路。
In the end I would like to run through a foreach
to get an image of each barcode which I can add to a pdf. 最后,我想遍历一个foreach
以获得每个条形码的图像,然后可以将其添加到pdf中。
There is a lot of documentation available on the ZF2 BarCode
class . ZF2 BarCode
类上有很多文档 。 There you find explained how to render your bar-code to an image: 在那里您找到了解释如何将条形码渲染为图像的方法:
$barCode = Barcode::factory(
'code39', 'image', $barcodeOptions, $rendererOptions
)->render();
To pass to your view you can do: 要传递您的意见,您可以执行以下操作:
new ViewModel(array('barCode' => $barCode));
I added them as a link in the html as noted in below link. 我将它们添加为html中的链接,如下面的链接所述。
How to render several barcodes with Zend 2? 如何使用Zend 2渲染多个条形码?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.