Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
620 views
in Technique[技术] by (71.8m points)

pdf generation - Zend Framework Render Barcodes Into PDF Pages

I'm trying to create PDF pages with barcodes that have correct margins to be printed on sheets of labels (If you have another idea of how to print barcodes onto labels without PDF generation, I'd love to hear it). Below is what I have currently for code:

$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'); 
  }
}

I'm currently getting an error "Invalid file path in: library/Zend/Pdf/FileParserDataSource/File.php on line 79 ()"

Any thoughts on why this is occurring? This happens when I try to render the barcode. Before that the code executes with no errors.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe that the complete answer to your question has since been added here: Zend Framework Render Barcodes Into Multiple PDF Pages with other content

The key seems to be:

  1. Create the Pdf library page content on a page.
  2. Add the Pdf library page to the pdf.
  3. Print the Barcode library barcodes onto that page of the pdf using something like Zend_Barcode::factory('code39', 'pdf', $barcodeOptions, $rendererOptions)->setResource($pdf, $page_index)->draw();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...