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.

I’ve recently had to solve some issues with long loading times regarding PDF documents.
In one case it involved a 24 bits PNG image with transparancy which caused the long loading time.
When I replaced it with a small GIF image without transparancy the PDF document loaded within 2 seconds.
In another case it was about the memory limit.
There was no out-of-memory error, but increasing it from 256 MB to 512 MB fixed the loading times in this case.

Your email address will not be published. Required fields are marked *

Comment

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.