2

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.

nwalke
  • 3,170
  • 6
  • 35
  • 60

2 Answers2

2

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();
Community
  • 1
  • 1
Tom Haws
  • 1,322
  • 1
  • 11
  • 23
1
$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-1', 'font' => __DIR__ . "/FRE3OF9X.TTF"); 

TTF file (FRE3OF9X.TTF or what have you) must exist.

akond
  • 15,865
  • 4
  • 35
  • 55
  • Any way to get the text it normally renders under the barcode to be readable? It's now a barcode as well. – nwalke Jan 30 '12 at 19:15
  • I'm using the same ttf you do in your example – nwalke Jan 30 '12 at 21:27
  • 1
    Err, I dont't know. I have never done it before, actually. The question just caught my eye. Maybe you should try another TTF. But I am not sure about it. – akond Jan 31 '12 at 07:20
  • I think the answer is to use a different PHP PDF class. Darn. – nwalke Jan 31 '12 at 17:51
  • 1
    You're probably right. This class is somewhat raw or incomplete, I'd say. I used to work with pdflib. But that was long ago. – akond Jan 31 '12 at 18:17
  • Note: You apparently can't use a monospaced font because the Zend_Pdf_Resource_Font classes don't know what to do with them when they are trying to calculate charWidths. – Tom Haws Oct 03 '12 at 22:05