Question

Hy guys,

how can i display a barcode with Zend_PDF ?

this is my code:

  $config = new Zend_Config(array(
                'barcode'        => 'code39',
                'barcodeParams'  => array('text' => '11020109'),
                'renderer'       => 'image',
                'rendererParams' => array('imageType' => 'gif'),
             ));
  $renderer = Zend_Barcode::factory($config)->render();

now how can i render it to my pdf? i try without succes with:

$barcode = Zend_Pdf_Image::imageWithPath($renderer);
$page->drawImage($barcode, 10, 510, 290, 550); 

thanks

Was it helpful?

Solution

The following should get you going, there is 3 things you have to change, your renderer, your method to render the barcode to the pdf and for some obscure reason, you have to include a font to your Zend_Barcode or you will get an error

$pdf = new Zend_Pdf();

// Your font (path might differ)
Zend_Barcode::setBarcodeFont(APPLICATION_PATH . '\..\data\resources\fonts\arial.ttf'); 

$config = new Zend_Config(
    array(
        'barcode'        => 'code39',
        'barcodeParams'  => array('text' => '11020109'),
        'renderer'       => 'pdf', // here is your new renderer
        'rendererParams' => array(), // you can define position offset here
    )
);

$pdfWithBarcode = Zend_Barcode::factory($config)->setResource($pdf)->draw(); // your new barcode renderer is defined here, from now on to add things to your pdf you need to use the new variable ($pdfWithBarcode)

// Save your pdf (path might differ)
$pdfWithBarcode->save(APPLICATION_PATH . '\..\data\testBarcode.pdf'); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top