我想从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