0

I have override invoice.php to insert new lines on my pdf invoice. It is working perfectly with positioning in right place.

However, when invoice content's total part goes to second page, my inserted new lines don't go to second page.

How to find out in my custom function that it goes to second page?

My Code is as below:

 public function getPdf($invoices = array())
    {
        $this->_beforeGetPdf();
        $this->_initRenderer('invoice');

        $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  = $this->newPage();
            $order = $invoice->getOrder();
            /* Add image */
            //$this->insertLogo($page, $invoice->getStore());

            /* insert custom company name */
            $this->_drawCompanyName($page,$invoice->getIncrementId());

            /* Add address */
            $this->insertAddress($page, $invoice->getStore());
            /* Add head */
            $this->insertOrder(
                $page,
                $order,
                Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()),
                'Invoice Date: ',$invoice->getCreatedAt()
            );
            /* Add document text and number */


            /*$this->insertDocumentNumber(
                $page,
                Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
            );*/
            /* Add table */
            $this->_drawHeader($page);

            /* Add body */
            foreach ($invoice->getAllItems() as $item){
                if ($item->getOrderItem()->getParentItem()) {
                    continue;
                }
                /* Draw item */
                $this->_drawItem($item, $page, $order);
                $page = end($pdf->pages);
            }
            /* Add totals */
            $this->insertTotals($page, $invoice);
            if ($invoice->getStoreId()) {
                Mage::app()->getLocale()->revert();
            }
        }
        /* call custom function */
        $this->_drawBottom($page);    //My Custom Function
        /* call custom function */
        $this->_drawNote($page);      //My Custom Function

        $this->_afterGetPdf();
        return $pdf;
    }

/* this is my custom function */
    protected function _drawBottom(Zend_Pdf_Page $page)
    {
        $this->_setFontRegular($page, 10);
    $page->setFillColor(new Zend_Pdf_Color_Rgb(0.95, 0.95, 0.95));
    $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
    $page->setLineWidth(0.5);
    $page->drawRectangle(25, $this->y, 570, $this->y -30);
    $this->y -= 10;
    $page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0));

    //columns headers
    $lines[0][] = array(
        'text' => Mage::helper('sales')->__(''),
        'feed' => 50
    );

    $lines[0][] = array(
        'text' => Mage::helper('sales')->__(''),
        'feed' => 200
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__(''),
        'feed'  => 350,
        'align' => 'right'
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__(''),
        'feed'  => 510,
        'align' => 'right'
    );

    $lines[1][] = array(
        'text' => Mage::helper('sales')->__('Store Keeper'),
        'feed' => 50
    );

    $lines[1][] = array(
        'text' => Mage::helper('sales')->__('Customer'),
        'feed' => 200
    );

    $lines[1][] = array(
        'text'  => Mage::helper('sales')->__('Delivery Boy'),
        'feed'  => 350,
    );

    $lines[1][] = array(
        'text'  => Mage::helper('sales')->__('Cashier'),
        'feed'  => 510,
    );


    $lineBlock = array(
        'lines'  => $lines,
        'height' => 15
    );

    $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
    $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
    $this->y -= 20;
    }

And it is looking like:

enter image description here

How to generate second page in my custom function and force content to second page when total goes to second page?

0

Check the code where you have added content for the fields Storekeeper, customer, delivery boy and cashier.
There must be some code similar as below :

   $lines[0] = array(array(
        'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
        'feed' => 35,
    ));

The 60 here is how many characters will be displayed per line ->getName(), 60, true,
Try increasing this number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.