首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Zend Framework将条形码呈现到PDF页面中

Zend Framework将条形码呈现到PDF页面中
EN

Stack Overflow用户
提问于 2012-01-29 06:07:06
回答 2查看 4.3K关注 0票数 2

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

代码语言:javascript
复制
$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'); 
  }
}

我当前收到一个错误消息"Invalid file path in: library/Zend/Pdf/FileParserDataSource/File.php on line 79 ()“。

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-30 03:42:02

代码语言:javascript
复制
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-1', 'font' => __DIR__ . "/FRE3OF9X.TTF"); 

TTF文件(FRE3OF9X.TTF或其他文件)必须存在。

票数 1
EN

Stack Overflow用户

发布于 2012-10-09 22:36:36

我相信你的问题的完整答案已经添加到这里:Zend Framework Render Barcodes Into Multiple PDF Pages with other content

关键似乎是:

  1. 在页面上创建Pdf库页内容。
  2. 将Pdf库页添加到pdf。
  3. 使用类似Zend_Barcode::factory('code39', 'pdf', $barcodeOptions, $rendererOptions)->setResource($pdf, $page_index)->draw();

的工具将条形码库条形码打印到pdf的该页面上

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9049046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档