2015-04-04 65 views
0

條碼不會打印到pdf文件的下一頁。讓我解釋。如果我想在每頁上打印60個條形碼和15個條形碼。它打印15個條形碼,其餘條形碼和頁面顯示空白。這裏是我的代碼Zend Framework 1.12條碼不會回顯到pdf文件的下一頁

public function generatebarcodeAction(){ 
    $this->_helper->layout()->disableLayout(); 
     $pdf = new Zend_Pdf(); 

     $hidden =$_POST['hidden']; // i want to barcode of this field. 
     // barcode should be print quantity from to quantity to 

     $quantityfrom =$_POST['quantity_from']; 
     $quantityto =$_POST['quantity_to']; 
     $rendererOptions = array(
     'topOffset' => 50, 
     'leftOffset' => 50 
     ); 
     Zend_Barcode::setBarcodeFont(dirname(ROOT_PATH) . '/inventory/library/Zend/Barcode/Object/fonts/open-sans/OpenSans-Semibold.ttf'); 

     $numberOfPages = $quantityto/15; 
     $equipmentCount = $quantityto; 
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 > 15) 
    { 
    $barcodesOnThisPage = 15; 
    $equipmentCount = $equipmentCount - 15; 
    } 
    else 
    { 
    $barcodesOnThisPage = $equipmentCount; 
    } 

for($i=$quantityfrom;$i<=$quantityto;$i++){ 
     $barcodeOptions = array('text' => $hidden.$i); 
     $rendererOptions = array('topOffset' => 50*$i); 
     $pdfWithBarcode = Zend_Barcode::factory('code39', 'pdf', 
     $barcodeOptions, $rendererOptions)->setResource($pdf)->draw(); 
     $pdfWithBarcode->save('testBarcode.pdf'); 

     } 
     $quantityfrom = $i; 
} 
} 

回答

1

在這段代碼中你是創建4個空白頁,然後繪製所有條碼在頁碼1.你不能看到45頁的條形碼,因爲他們的利潤率比頁面高度更大! 您可能需要將條碼添加到$pages而不是$pdf。 小心你應該使用for而不是foreach重寫$page

+0

感謝您的善意幫助。它爲我工作。 – 2015-04-06 08:19:43

相關問題