Question

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
);
Was it helpful?

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top