【问题标题】:Zend Framework Render Barcodes Into PDF PagesZend Framework 将条码渲染成 PDF 页面
【发布时间】:2012-01-28 22:07:05
【问题描述】:

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

$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'); 
  }
}

我目前收到错误“第 79 行 () 上的 library/Zend/Pdf/FileParserDataSource/File.php 中的文件路径无效”

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

【问题讨论】:

  • 第 79 行是我在 Zend_Barcode::factory 上调用 render() 的那一行

标签: zend-framework pdf-generation barcode


【解决方案1】:

我相信您的问题的完整答案已添加到此处: Zend Framework Render Barcodes Into Multiple PDF Pages with other content

关键似乎是:

  1. 在页面上创建 Pdf 库页面内容。
  2. 将 Pdf 库页面添加到 pdf。
  3. 使用Zend_Barcode::factory('code39', 'pdf', $barcodeOptions, $rendererOptions)-&gt;setResource($pdf, $page_index)-&gt;draw(); 之类的方式将条形码库条形码打印到 pdf 的该页面上

【讨论】:

  • 谢谢!我一定要检查一下。
【解决方案2】:
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-1', 'font' => __DIR__ . "/FRE3OF9X.TTF"); 

TTF 文件(FRE3OF9X.TTF 或你有什么)必须存在。

【讨论】:

  • 有什么方法可以让它通常在条形码下呈现的文本可读?它现在也是条码。
  • 我使用的 ttf 与您在示例中使用的 ttf 相同
  • 呃,我不知道。实际上,我以前从未这样做过。这个问题刚刚引起了我的注意。也许你应该尝试另一个 TTF。但我不确定。
  • 我认为答案是使用不同的 PHP PDF 类。该死。
  • 你可能是对的。我想说,这门课有点原始或不完整。我曾经使用pdflib。但那是很久以前的事了。
猜你喜欢
  • 1970-01-01
  • 2023-03-28
  • 2013-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-04
  • 2013-07-20
  • 2014-09-18
相关资源
最近更新 更多