2015-04-04 38 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