2012-01-28 63 views
2

我试图创建带有正确页边距的条形码的PDF页面,并将其打印在标签上(如果您有另一个关于如何在没有生成PDF的情况下将条形码打印到标签上的想法, d爱听到它)。下面是我当前的代码:Zend Framework将条形码渲染为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'); 
    } 
} 

我目前得到一个错误 “在无效的文件路径:库/的Zend/PDF/FileParserDataSource/File.php上线79()”

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

+1

哪一个是线79的PDF页面吗? – ACNB 2012-01-29 16:09:26

+0

79行是我在Zend_Barcode :: factory上调用render()的地方 – tubaguy50035 2012-01-30 19:02:47

回答

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

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

+0

任何方式来获取它通常在条形码下呈现的文本是可读的吗?现在它也是一个条形码。 – tubaguy50035 2012-01-30 19:15:41

+0

我在你的例子中使用相同的ttf – tubaguy50035 2012-01-30 21:27:04

+1

错误,我不知道。实际上,我从来没有做过。这个问题引起了我的注意。也许你应该尝试另一个TTF。但我不确定。 – akond 2012-01-31 07:20:20

2

我认为,完整的回答你的问题已经被这里补充说: 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();
+0

感谢您的支持!我一定要检查一下。 – tubaguy50035 2012-10-09 14:41:27