January 2, 2010

Invoice printing to PDF taking to long in Magento?

Recently I was assigned a task to check the slowness of PDF printing on invoice page of Magento admin. It took him around 5minutes to print PDF (return PDF document on Invoice page). After diving into the code trying to trace the issue I found what was the cause of slow printing. PDF document that gets created has the ability to include the logo in header.
Code that adds the image into the header is located under the method named “getPdf()” in “app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php” file. There is a line that says “$this->insertLogo($page, $invoice->getStore());”.
Method “insertLogo()” is located under “app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php”. When commented out the invoice gets printed to PDF in a matter of 2-3 seconds. However, simply commenting out the method is not the proper solution. After short introspection, conclusion was that the image assigned as logo was to big in dimensions (around 3500x… px). Reducing logo in size drastically improved generation of PDF.
Hope this helps someone with the same “slow invoice printing” issue.

2 comments:

  1. Changing the default font used by Magento to print Invoice PDFs will reduce the size a lot.

    After changing the PDf font from default one to other true type font family the size has got reduced dramatically.

    Hope this helps some one.

    BTW its really a nice blog for Magento :-)

    ReplyDelete