2012-01-28 60 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