【问题标题】:display a barcode with Zend_PDF使用 Zend_PDF 显示条形码
【发布时间】:2011-11-16 13:35:38
【问题描述】:

大家好,

如何使用 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); 

谢谢

【问题讨论】:

    标签: zend-framework zend-pdf


    【解决方案1】:

    以下内容应该可以帮助您进行操作,您必须更改 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'); 
    

    【讨论】:

    • 我试了一下,但收到此错误:PDF 名称中不允许有空字符
    • 你给Zend_Barcode设置的字体是否存在于你给定的路径中?
    • 您的输出文件名中是否有任何特殊字符?
    • 我认为没有.. $pdf->save("fogliovendita.pdf");
    • 最后一行错误:$pdfWithBarcode 是 Zend_Barcode_Renderer_Pdf 的一个实例,你需要 Zend_Pdf。我想你的意思是 $pdf->save(...);或者 API 可能同时发生了变化(我正在查看 zf 1.12)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多