Zend Framework 将条形码渲染成 PDF 页面 [英] Zend Framework Render Barcodes Into PDF Pages

查看:20
本文介绍了Zend Framework 将条形码渲染成 PDF 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建带有条形码的 PDF 页面,这些条形码具有要打印在标签页上的正确边距(如果您对如何在不生成 PDF 的情况下将条形码打印到标签上有其他想法,我很想听听).以下是我目前的代码:

I'm trying to create PDF pages with barcodes that have correct margins to be printed on sheets of labels (If you have another idea of how to print barcodes onto labels without PDF generation, I'd love to hear it). Below is what I have currently for code:

$pdf = new Zend_Pdf();
for($i = 1; $i <= $numberOfPages; $i++)
{
  $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
  $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 20);
  $pdf->pages[] = $page;
}
foreach($pdf->pages as $id => $page)
{
  if($equipmentCount > 10)
  {
    $barcodesOnThisPage = 10;
    $equipmentCount = $equipmentCount - 10;
  }
  else
  {
    $barcodesOnThisPage = $equipmentCount;
  }
  for($i = 1; $i <= $barcodesOnThisPage; $i++)
  {
    //Zend_Barcode::setBarcodeFont();
    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK-1'); 
    $rendererOptions = array('topOffset' => 50);
    $pdf = Zend_Barcode::factory('code39', 'pdf', 
    $barcodeOptions, $rendererOptions)->setResource($pdf)->render(); 
    die;
    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK-2'); 
    $rendererOptions = array('topOffset' => 100); 
    $pdfBarcode = Zend_Barcode::factory('code39', 'pdf', 
    $barcodeOptions, $rendererOptions)->setResource($pdf)->draw(); 
    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK-3'); 
    $rendererOptions = array('topOffset' => 150); 
    $pdfBarcode = Zend_Barcode::factory('code39', 'pdf', 
    $barcodeOptions, $rendererOptions)->setResource($pdf)->draw(); 
    // and the end render your Zend_Pdf 
    /$pdfBarcode->save('testBarcode.pdf'); 
  }
}

我目前收到错误无效的文件路径:library/Zend/Pdf/FileParserDataSource/File.php on line 79 ()"

I'm currently getting an error "Invalid file path in: library/Zend/Pdf/FileParserDataSource/File.php on line 79 ()"

关于为什么会发生这种情况的任何想法?当我尝试渲染条形码时会发生这种情况.在此之前,代码执行没有错误.

Any thoughts on why this is occurring? This happens when I try to render the barcode. Before that the code executes with no errors.

推荐答案

$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-1', 'font' => __DIR__ . "/FRE3OF9X.TTF"); 

TTF 文件(FRE3OF9X.TTF 或您拥有的)必须存在.

TTF file (FRE3OF9X.TTF or what have you) must exist.

这篇关于Zend Framework 将条形码渲染成 PDF 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆