1

Zend PDF から生成された Magento 請求書で、Zend Barcode からレンダリングされたバーコードを取得しようとしています。

私のスタンドアロン テスト バーコード スクリプトは次のようになり、意図したとおりにバーコードとテキスト「testing」を含む 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());

.../* 請求書の作成を続行 */...

適合したバーコード スクリプトは、このように一部のアイテムの下に挿入されます。

   /* 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 ドキュメントで実行すると、124 行目の lib/Zend/Barcode/Renderer/Pdf.php の非オブジェクトでメンバ関数 getHeight() への呼び出しというエラーが返されます。

行 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 がそこで失敗する理由がわかりません。

4

2 に答える 2

3

私は同じ問題に遭遇しました.問題は以下のコードにあります:

$renderer = Zend_Barcode::factory('code128', 'pdf', $barcodeOptions, 
                $rendererOptions)->setResource($pdf, $page)->draw();

serResource に指定した $page 変数は、実際の pdf ページです。ページ番号である必要があります。たとえば、次のコードは最初のページにバーコードを描画します。必要に応じて $pageNo を変更するだけです。

/* 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 */
于 2013-11-06T11:46:49.683 に答える