You need to override the Mage_Sales_Model_Order_Pdf_Invoice
class via the
Magento_root/app/code/local/Mage
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');
$current++;
}
parent::_afterGetPdf();
}
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
).