我想生成条形码并在按钮下方,以便用户只需单击它然后打印即可。但是我无法做到这一点所以现在我有了这段代码:
$page = new Zend_Pdf();
$imageResource = Zend_Barcode::draw('code39', 'image', $barcodeOptions, $rendererOptions);
imagejpeg($imageResource, 'barcode.jpg', 100);
$img = Zend_Pdf_Image::imageWithPath('barcode.jpg');
//echo $randomTxt;
echo '<br/>';
echo '<img src="'. base_url() .'/images/logo.png"/>';
echo '<img src="'. $img .'"/>';
但是我收到以下错误:
遇到PHP错误
严重程度:4096
消息:类的对象 Zend_Pdf_Resource_Image_Jpeg不能 被转换为字符串
文件名: 视图/ vista_codigoDeBarras.php
行号:19
我不知道如何完成我需要的东西,现在有点紧急= /任何想法我怎么能做到这一点?我正在使用Zend框架在CodeIgniter
中生成de条形码答案 0 :(得分:0)
我对你想要实现的目标感到有些困惑,但Zend_Pdf_Image
是为了将图像添加到PDF文档而做的。鉴于您的要求:
我想生成条形码和 在按钮下方以便用户 只需点击它然后打印即可。
有几种方法可以实现这一目标。首先是创建一个简单输出条形码图像的PHP脚本,并将其用作图像的src
属性:
// Only the text to draw is required
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
// No required options
$rendererOptions = array();
// Draw the barcode in a new image,
// send the headers and the image
Zend_Barcode::factory(
'code39', 'image', $barcodeOptions, $rendererOptions
)->render();
来源:http://framework.zend.com/manual/en/zend.barcode.creation.html
然后,用户只需在新标签页中打开图像,或下载并打印即可。
另一种选择是为他们提供PDF下载,这比我可以花时间提供示例代码要复杂一点,但是这个链接解释了如何使用Zend_PDF
类生成PDF: / p>