php - Magento: Barcode on Printed Invoice using Zend Barcode and Zend PDF -
i trying barcode rendered zend barcode on magento invoice generated zend pdf
my standalone test barcode script looks , generate pdf document barcode , text 'testing' intended.
$pdf = new zend_pdf(); $page = new zend_pdf_page(zend_pdf_page::size_a4); $page->setfont(zend_pdf_font::fontwithname(zend_pdf_font::font_helvetica), 20); //$font = zend_pdf_font::fontwithname(zend_pdf_font::font_times_roman); zend_barcode::setbarcodefont('gothic.ttf'); $filename= 'barcode.pdf'; $barcodeno = '99700161bst004008501022006714'; $barcodeoptions = array( 'text' => $barcodeno, 'barheight'=> 74, 'factor'=>3.98, //'fontsize' =>20, //'drawtext'=> false ); $rendereroptions = array(); $renderer = zend_barcode::factory( 'code128', 'pdf', $barcodeoptions, $rendereroptions )->setresource($pdf, $page)->draw(); $page->drawtext('test', 25, 720, 'utf-8'); $pdf->pages[] = $page; $pdf->save($filename);
the magento invoices pdf initiated so.
$pdf = new zend_pdf(); $this->_setpdf($pdf); $style = new zend_pdf_style(); $this->_setfontbold($style, 10); foreach ($invoices $invoice) { if ($invoice->getstoreid()) { mage::app()->getlocale()->emulate($invoice->getstoreid()); mage::app()->setcurrentstore($invoice->getstoreid()); } $page = $pdf->newpage(zend_pdf_page::size_a4); $pdf->pages[] = $page; $order = $invoice->getorder(); /* add image */ $this->insertlogo($page, $invoice->getstore());
.../* continue building invoice */...
the adapted barcode script inserted below of items so.
/* start barcode */ $page->setfont(zend_pdf_font::fontwithname(zend_pdf_font::font_helvetica), 20); zend_barcode::setbarcodefont('/srv/magento/media/fonts/gothic.ttf'); $barcodeoptions = array( 'text' => $trackingnumber, 'barheight'=> 74, 'factor'=>3.98 ); $rendereroptions = array('height'=> 800,'width'=> 800); $renderer = zend_barcode::factory( 'code128', 'pdf', $barcodeoptions, $rendereroptions )->setresource($pdf, $page)->draw(); /* end barcode */
however when running in magento invoice pdf doc returns error call member function getheight() on non-object in lib/zend/barcode/renderer/pdf.php on line 124.
line 124 contains
protected function _initrenderer() { if ($this->_resource === null) { $this->_resource = new zend_pdf(); $this->_resource->pages[] = new zend_pdf_page( zend_pdf_page::size_a4 ); } $pdfpage = $this->_resource->pages[$this->_page]; $this->_adjustposition($pdfpage->getheight(), $pdfpage->getwidth()); }
which appears requesting pdfpage height, can't see why fail when put in barcode script and/or why pdfpage->getheight fail there.
i have came accross same problem.the problem in code below:
$renderer = zend_barcode::factory('code128', 'pdf', $barcodeoptions, $rendereroptions)->setresource($pdf, $page)->draw();
the $page variable gave serresource actual pdf page. should page number. example code below draw barcode on first page. change $pageno according need.
/* start barcode */ $page->setfont(zend_pdf_font::fontwithname(zend_pdf_font::font_helvetica), 20); zend_barcode::setbarcodefont('/srv/magento/media/fonts/gothic.ttf'); $barcodeoptions = array( 'text' => $trackingnumber, 'barheight'=> 74, 'factor'=>3.98 ); $pageno = 0; $rendereroptions = array('height'=> 800,'width'=> 800); $renderer = zend_barcode::factory( 'code128', 'pdf', $barcodeoptions, $rendereroptions )->setresource($pdf, $pageno)->draw(); /* end barcode */
Comments
Post a Comment