开发者

Adding a button and image using Zend Framework in Codeigniter

I want to generate a barcode and underneath a button so that the user can just click it and then print. However I haven't been able to do this so now I have this code:

$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;
    e开发者_如何转开发cho '<br/>';
    echo '<img src="'. base_url() .'/images/logo.png"/>';
    echo '<img src="'. $img .'"/>';

However I get the following error:

A PHP Error was encountered

Severity: 4096

Message: Object of class Zend_Pdf_Resource_Image_Jpeg could not be converted to string

Filename: views/vista_codigoDeBarras.php

Line Number: 19

I have no idea how to accomplish what I need and it's sort of urgent now =/ any idea how I can do it? I'm using Zend framework to generate de barcode within CodeIgniter


I'm a bit confused on what you're trying to achieve, but Zend_Pdf_Image is made for adding images to PDF documents. Given your requirement:

I want to generate a barcode and underneath a button so that the user can just click it and then print.

There are a few ways you can accomplish this. First off is to create a php script that simply outputs a barcode image, and use that as the src attribute of the image:

// 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();

Source: http://framework.zend.com/manual/en/zend.barcode.creation.html

The user can then just open the image in a new tab or download and print it.

The other option is to offer them a PDF download, which is a bit more complicated than I can devote the time to providing sample code for, but this link explains how to generate PDFs using the Zend_PDF class:

http://devzone.zend.com/article/2525

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜