I'm facing problem for adding a number of pages in single invoice. For example one invoice has 3 pages and I wanted to display first page 1 of 3 in pdf invoice and second page, page 2 of 3 and last page 3 of 3 on PDF invoice.

How to implement this page of n in PDF invoice in magento?

1 Answer 1


You need to override the Mage_Sales_Model_Order_Pdf_Invoice class via the


directory or rewrite it in your custom extension.

Since you need to know a total of pages, so you need to redefine the _afterGetPdf function of the parent class (Mage_Sales_Model_Order_Pdf_Abstract) and add the following code:

protected function _afterGetPdf()
    $pages = $this->_getPdf()->pages;
    $total = count($pages);

    $current = 1;
    foreach ($pages as $page) {
        $page->drawText(Mage::helper('sales')->__('page %d of %d', $current, $total), 35, 30, 'UTF-8');


Also, you can play with coordinates for moving your text.
Please pay attention that the point with the 0,0 coordinates is in the lower left corner.
Also you can try to take advantage of the getAlignRight and the getAlignCenter functions of the parent class (Mage_Sales_Model_Order_Pdf_Abstract).

  • how can we do this for magento 2? Dec 8, 2022 at 5:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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