Search code examples
phpzend-frameworkzend-framework2barcodebarcode-printing

How to render several barcodes with Zend 2?


I'm trying print several barcodes using the Zend\Barcode namespace.

The problem is reading the manual I can't print more than one barcode.

I can't print a echo before the barcode too.

How can I print several barcodes and texts together?

The code I'm using is similar to this one:

use Zend\Barcode\Barcode;

$barcodeOptions = array('text' => '123456');
$rendererOptions = array();

Barcode::render(
    'code39', 'image', $barcodeOptions, $rendererOptions
);

$barcodeOptions = array('text' => '654321');
Barcode::render(
    'code39', 'image', $barcodeOptions, $rendererOptions
);

Solution

  • Barcode::render() generates an image, not an HTML page with images in it. You'll need to do something like this:

    barcode.php:

    use Zend\Barcode\Barcode;
    $barcodeOptions = array('text' => $_GET['code']);
    $rendererOptions = array();
    Barcode::render(
        'code39', 'image', $barcodeOptions, $rendererOptions
    );
    

    And then in your HTML, you reference that script as if it were an image:

    <img src="http://domain.com/barcode.php?code=123456" />
    <img src="http://domain.com/barcode.php?code=654321" />