1

嗨,伙计们,

如何使用 Zend_PDF 显示条形码?

这是我的代码:

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

现在我怎样才能把它渲染成我的pdf?我尝试没有成功:

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

谢谢

4

1 回答 1

2

以下内容应该可以帮助您进行,您必须更改 3 件事,您的渲染器,将条形码渲染为 pdf 的方法,以及出于某种模糊的原因,您必须在 Zend_Barcode 中包含字体,否则您将收到错误

$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'); 
于 2011-11-16T15:34:54.283 回答