Invoice printing to PDF taking to long in Magento?

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.

You made it all the way down here so you must have enjoyed this post! You may also like:

Adding gallery tab to a CMS page Antun Martinovic
Antun Martinovic, | 5

Adding gallery tab to a CMS page

How I learned to stop worrying and love 3rd party modules for Magento Luka Rajcevic
Luka Rajcevic, | 2

How I learned to stop worrying and love 3rd party modules for Magento

How to manage clients, pressure and stress Zelimir Gusak
Zelimir Gusak, | 3

How to manage clients, pressure and stress


  1. when i print order as a customer. company logo is to large its cover the whole header part. so how can i reduce the logo size.?

  2. can you help me in solving this problem as i am facing an error while printing invoice from the backend of magento the error message are

    There has been an error processing your request

    Table length (854551) not within expected range

    #0 /home/royal/public_html/lib/Zend/Pdf/Font.php(615): Zend_Pdf_Font::_extractTrueTypeFont(Object(Zend_Pdf_FileParserDataSource_File), 0)
    #1 /home/royal/public_html/app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php(807): Zend_Pdf_Font::fontWithPath(‘/home/royal/pub…’)
    #2 /home/royal/public_html/app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php(113): Mage_Sales_Model_Order_Pdf_Abstract->_setFontBold(Object(Zend_Pdf_Style), 10)
    #3 /home/royal/public_html/app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php(119): Mage_Sales_Model_Order_Pdf_Invoice->getPdf(Array)
    #4 /home/royal/public_html/app/code/core/Mage/Adminhtml/controllers/Sales/Order/InvoiceController.php(489): Mage_Adminhtml_Controller_Sales_Invoice->printAction()
    #5 /home/royal/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_Sales_Order_InvoiceController->printAction()
    #6 /home/royal/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch(‘print’)
    #7 /home/royal/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(177): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
    #8 /home/royal/public_html/app/code/core/Mage/Core/Model/App.php(356): Mage_Core_Controller_Varien_Front->dispatch()
    #9 /home/royal/public_html/app/Mage.php(695): Mage_Core_Model_App->run(Array)
    #10 /home/royal/public_html/index.php(88): Mage::run(‘base’, ‘website’)
    #11 {main}

    Error log record number: 993164297967

  3. 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.

  4. As it turns out this is true for the wide spread Fooman PdfCustomizer module. All PHP PDF implementations like tcpdf or Zend_PDF don’t cope very well with large images.

    The print action should produce the PDF file within 400~700ms (VPS, opcode caching, decend config).

    Thank you for sharing Branko. Saved me some profiling / debugging!

Leave a Reply

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

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>.

Tell us about your project

Drop us a line. We'd love to know more about your project.