Zend_PDF & Zend_Barcode

For programming and general questions on Zend Framework

Zend_PDF & Zend_Barcode

Postby artfabio on Thu Jul 12, 2012 11:50 am

Hi,
I have a problem with Zend_Pdf.
Should I create a table that has a barcode for each record. Studying the documentation I found this code:

private function generaBarcode($nrr) {
/*Barcode*/
$config = new Zend_Config ( array ('barcode' => 'code39', //EAN13
'barcodeParams' => array ('text' => $nrr ),
'renderer' => 'image',
'rendererParams' => array ('imageType' => 'jpeg' )
)
);

$renderer = Zend_Barcode::factory ( $config )->draw ();
$im = imagejpeg ( $renderer, "barcode.jpg", 50 );
$barcode = Zend_Pdf_Image::imageWithPath ( "barcode.jpg" );

return $barcode;
}

public function stampaBar() {
$server = "*.*.*.*";
$user = "LEONI";
$psw = "LEONILEONI";
$conn = i5_connect ( $server, $user, $psw );

$dollaro = chr ( 36 );
$lib = "A3" . $dollaro . "DB";
$sql = "select YLNRR
from $lib/YLDPHP9P
where YLSSRK=' '
order by YLNRR";

$result = i5_query ( $sql, $conn );
$pdf = new Zend_Pdf (); //Creiamo il documento PDF
$page = $pdf->newPage ( Zend_Pdf_Page::SIZE_A4 );
$y = 810;
$cont = 0;

while ( ($row = i5_fetch_assoc ( $result )) && ($cont<10) ) {

$barcode = $this->generaBarcode ( $row ['YLNRR'] );
$page->drawImage ( $barcode, 10, $y, 150, $y + 35 );
echo "Stampato il barcode $cont <br/>";
unlink ( "barcode.jpg" );
$y -= 80;
$cont ++;
}
$pdf->pages [] = $page;
$pdf->save ( "bar.pdf" );
i5_close ( $conn );
}

Using this code everything works but the time to create the pdf file is too big: 10 minutes for about 3000 records.

Can you help me how I can improve the time?
Thank you,
Fabio
artfabio
 
Posts: 7
Joined: Fri Apr 20, 2012 3:26 pm

Re: Zend_PDF & Zend_Barcode

Postby artfabio on Thu Jul 12, 2012 4:34 pm

What is wrong?

Code: Select all
ini_set('include_path', '/usr/local/zendsvr/share/ZendFramework/library/');
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);

$pdf = new Zend_Pdf();
//... your work

//a font is mandatory for Pdf
Zend_Barcode::setBarcodeFont('times.ttf');

$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-1');
$rendererOptions = array('topOffset' => 50);
$pdfWithBarcode = Zend_Barcode::factory('code39', 'pdf',
$barcodeOptions, $rendererOptions)->setResource($pdf)->draw();

$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-2');
$rendererOptions = array('topOffset' => 100);
$pdfWithBarcode = Zend_Barcode::factory('code39', 'pdf',
$barcodeOptions, $rendererOptions)->setResource($pdfWithBarcode)->draw();

$barcodeOptions = array('text' => 'ZEND-FRAMEWORK-3');
$rendererOptions = array('topOffset' => 150);
$pdfWithBarcode = Zend_Barcode::factory('code39', 'pdf',
$barcodeOptions, $rendererOptions)->setResource($pdfWithBarcode)->draw();

// and the end render your Zend_Pdf
$pdfWithBarcode->save('testBarcode.pdf');


The error is:
Fatal error: Uncaught exception 'Zend_Pdf_Exception' with message 'Null character is not allowed in PDF Names' in /usr/local/zendsvr/share/ZendFramework/library/Zend/Pdf/Element/Name.php:56 Stack trace: #0 /usr/local/zendsvr/share/ZendFramework/library/Zend/Pdf/Resource/Font/CidFont.php(121): Zend_Pdf_Element_Name->__construct('?T?i?m?e?s?N?e?...') #1 /usr/local/zendsvr/share/ZendFramework/library/Zend/Pdf/Resource/Font/CidFont/TrueType.php(64): Zend_Pdf_Resource_Font_CidFont->__construct(Object(Zend_Pdf_FileParser_Font_OpenType_TrueType), 0) #2 /usr/local/zendsvr/share/ZendFramework/library/Zend/Pdf/Font.php(709): Zend_Pdf_Resource_Font_CidFont_TrueType->__construct(Object(Zend_Pdf_FileParser_Font_OpenType_TrueType), 0) #3 /usr/local/zendsvr/share/ZendFramework/library/Zend/Pdf/Font.php(615): Zend_Pdf_Font::_extractTrueTypeFont(Object(Zend_Pdf_FileParserDataSource_File), 0) #4 /usr/local/zendsvr/share/ZendFramework/library/Zend/Barcode/Renderer/Pdf.php(196): Zend_Pdf_Font::fontWithPath('times.ttf') #5 /usr/local/zendsvr/ in /usr/local/zendsvr/share/ZendFramework/library/Zend/Pdf/Font.php on line 727
artfabio
 
Posts: 7
Joined: Fri Apr 20, 2012 3:26 pm

Re: Zend_PDF & Zend_Barcode

Postby ringer on Fri Aug 31, 2012 9:51 pm

Did you figure this out? I am having the exact same issue. This exception is thrown when the ->draw() runs. I have compared my ttf file on my local C: and server and they are the same so is not my .ttf as far as I can tell. For now, I set the barcode option to drawText' => false and draw the text below the barcode. But that's real inconvenient. And I really don't want to save an image to disk and do a drawImage() and unlink the image. Thanks.

Chris R
ringer
 
Posts: 5
Joined: Tue Nov 08, 2011 3:21 pm

Re: Zend_PDF & Zend_Barcode

Postby adam1254 on Mon Feb 25, 2013 4:24 am

Same problem with me. Have you guys found a feasible solution to this problem? If yes, please offer me some help.









----------------------------------------
The world can not stop QR code
Barcodelib for development
adam1254
 
Posts: 1
Joined: Mon Feb 25, 2013 4:19 am


Return to Zend Framework

Who is online

Users browsing this forum: Google [Bot] and 6 guests