0

I would like to render multiple Zend Framework 2 barcodes on a page.

I have been following this example (although it is for ZF1) Zend Framework Render Barcodes Into PDF Pages

I am currently using DOMPDFModule to create a pdf.

How do I display the barcode using 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:

"resource(459) of type (gd)"

When I use imagegd() I get a bunch of symbols.

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.

Community
  • 1
  • 1
Matt
  • 383
  • 1
  • 5
  • 20

2 Answers2

1

There is a lot of documentation available on the ZF2 BarCode class. 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)); 
Wilt
  • 41,477
  • 12
  • 152
  • 203
  • I understand this works in the controller. I want to make a number of barcodes and render them in the view – Matt Dec 08 '15 at 15:58
  • @Matt You can easily render them in the controller and pass them in the `variables` array to the view like you do with other parameters. – Wilt Dec 08 '15 at 15:59
  • I tried this previously but whenever I run the render it seems to stop the code there. When I run the code you suggested above it displays just the barcode on the screen regardless of what is in the view. The result is an html page with the following view added http://localhost/public/barcode – Matt Dec 08 '15 at 16:17
  • to clarify above. It doesn't render the view at all. It seems to stop at the controller with the render. – Matt Dec 09 '15 at 03:30
0

I added them as a link in the html as noted in below link.

How to render several barcodes with Zend 2?

Community
  • 1
  • 1
Matt
  • 383
  • 1
  • 5
  • 20