我想從Zend的條形碼從Zend的PDF生成的Magento的發票渲染條形碼的Magento:使用Zend條碼和Zend PDF
我的獨立測試條碼腳本是這樣的,並會生成一個條形碼上打印的發票包含條形碼和文本「測試」的PDF文檔。
$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);
Magento的發票PDF開始像這樣。
$pdf = new Zend_Pdf();
$this->_setPdf($pdf);
$style = new Zend_Pdf_Style();
$this->_setFontBold($style, 10);
foreach ($invoices as $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());
.../*繼續建設INVOICE */...
適配的條形碼腳本插入下面的一些像這樣的項目。
/* 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 */
然而,在Magento的發票PDF文檔運行時,它返回錯誤調用一個成員函數的getHeight()在LIB非對象上/ Zend的/條形碼/渲染器/ Pdf.php上線124
124行包含
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());
}
這似乎是請求pdfPage高度,但我不明白爲什麼當我把我的條碼腳本和/或爲什麼pdfPage->的getHeight將只會失敗在那裏失敗。
謝謝,我還需要先添加頁面。例如$ pdf-> pages [] = $ pdf-> newPage(Zend_Pdf_Page :: SIZE_A4); – 2016-02-11 00:21:42