PDF generation took too long

Hello.

I checked the FAQ & other tickets but did not find a similar one.
Just installed InvoicePlane to my vesta web server with letsencrypt ssl without proxies (ex. Cloudflare)
PHP 5.6.29-0+deb8u1

The panel seems to work well … when i try to generate a PDF from invoice (“Download PDF”) … it tooks about 120 seconds, but it generates well after this long time.
Where do i need to search the problem source? What is the solution?

DEBUG - 2017-07-31 09:06:39 --> UTF-8 Support Enabled
DEBUG - 2017-07-31 09:06:39 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2017-07-31 09:06:39 --> Invoices MX_Controller Initialized
DEBUG - 2017-07-31 09:06:39 --> Config file loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/config/invoice_plane.php
DEBUG - 2017-07-31 09:06:39 --> Encryption: Auto-configured driver 'openssl'.
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/settings/models/Mdl_settings.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/controllers/../modules/layout/controllers/Layout.php
DEBUG - 2017-07-31 09:06:39 --> Layout MX_Controller Initialized
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/invoices/models/Mdl_invoices.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/invoices/models/Mdl_items.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/invoices/models/Mdl_invoice_tax_rates.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/custom_fields/models/Mdl_custom_fields.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/payment_methods/models/Mdl_payment_methods.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/custom_fields/models/Mdl_invoice_custom.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/custom_fields/models/Mdl_client_custom.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/modules/custom_fields/models/Mdl_user_custom.php
DEBUG - 2017-07-31 09:06:39 --> File loaded: /home/admin/web/*DOMAIN-CENSORED*/public_html/application/views/invoice_templates/pdf/InvoicePlane - paid.php
**DEBUG - 2017-07-31 09:08:39 --> Total execution time: 120.3361**
1 Like

Having same issues. Just installed today so I have the latest version 1.5 running on iis 8/windows server 2012 with 64 bit php 7.1 non thread safe (tried different versions of php with same results). Everything runs fast until the pdf generation which is taking 4 minutes. No error logs though on my end. I have also tried changing the configuration from development to production as mentioned fixed the issue on older versions of the invoice plane software. Love the software but this slowness is driving me crazy. Also, note that i havent created any custom templates. Its the out of box templates with 1 line item and no images what so ever. Any help is much appreciated.

Also having the same issue on my Mac. Total execution time: 240 second everytime.

In my case issue is

From here https://github.com/mpdf/mpdf#requirements

mPDF has some problems with fetching external HTTP resources with single threaded servers such as `php -S`. A proper
server such as nginx (php-fpm) or Apache is recommended.
2 Likes

I have a same issue.

And I am a Cloudflare user too. (Cloudflare offers free authoritative Domain Name System (DNS) service)

When I disable Cloudflare proxies(CDN feature), the PDF generator need a long time generate the invoice PDF.

I want find out what is the problem.

I think that is not invoiceplane problem. But I cannot find out that is Cloudflare problem.

Anyone can help?

Is this an IP related problem?

If it is not specifically related to IP, you should consider posting your question to the mPDF forum as explained here.

If this is an IP issue, please, tell us which version you are using and detailed instructions to reproduce the problem so we can test and debug it. Last, can you reproduce the problem in the demo site?

thank you for the information.

Hi,
did you resolve this issue?

I moved my webserver to FreeNAS 11.2 iocage, installed php 7.3, apache24 with mariadb10.4, but I still have long time to generate a PDF from invoice.

DEBUG - 2019-09-06 15:18:44 --> UTF-8 Support Enabled
DEBUG - 2019-09-06 15:18:44 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2019-09-06 15:18:44 --> Invoices MX_Controller Initialized
DEBUG - 2019-09-06 15:18:44 --> Config file loaded: /usr/local/www/apache24/data/ip/application/config/invoice_plane.php
DEBUG - 2019-09-06 15:18:44 --> Encryption: Auto-configured driver 'openssl'.
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/settings/models/Mdl_settings.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/settings/models/Mdl_versions.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/controllers/../modules/layout/controllers/Layout.php
DEBUG - 2019-09-06 15:18:44 --> Layout MX_Controller Initialized
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/invoices/models/Mdl_invoices.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/invoices/models/Mdl_items.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/invoices/models/Mdl_invoice_tax_rates.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/custom_fields/models/Mdl_custom_fields.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/payment_methods/models/Mdl_payment_methods.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/payments/models/Mdl_payments.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/custom_fields/models/Mdl_invoice_custom.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/custom_values/models/Mdl_custom_values.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/custom_fields/models/Mdl_client_custom.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/modules/custom_fields/models/Mdl_user_custom.php
DEBUG - 2019-09-06 15:18:44 --> File loaded: /usr/local/www/apache24/data/ip/application/views/invoice_templates/pdf/InvoicePlane.php
DEBUG - 2019-09-06 15:20:44 --> Total execution time: 120.7688

There could be any number of things go wrong.
Did you check that the database is not the culprit here?

Hi, Im not sure what to look at, MariaDB its with standard settings. I can check settings with phpMyAdmin.

That probably won’t tell you much.

If you have any dev skills, you could comment out the line that does the actual PDF generation and echo the template output to the screen. If it still takes a long time the issue is with the database. Otherwise the PDF generation is suspect.

application/helpers/pdf_helper.php

function generate_invoice_pdf($invoice_id, $stream = true, $invoice_template = null, $is_guest = null)
{
    ....

    $html = $CI->load->view('invoice_templates/pdf/' . $invoice_template, $data, true);

    $CI->load->helper('mpdf');
    return pdf_create($html, trans('invoice') . '_' . str_replace(array('\\', '/'), '_', $invoice->invoice_number),
        $stream, $invoice->invoice_password, true, $is_guest, $include_zugferd, $associatedFiles);
}

becomes

function generate_invoice_pdf($invoice_id, $stream = true, $invoice_template = null, $is_guest = null)
{
    ....

    $html = $CI->load->view('invoice_templates/pdf/' . $invoice_template, $data, true);
echo $html;
    // $CI->load->helper('mpdf');
   //  return pdf_create($html, trans('invoice') . '_' . str_replace(array('\\', '/'), '_', $invoice->invoice_number),
  //      $stream, $invoice->invoice_password, true, $is_guest, $include_zugferd, $associatedFiles);
}

The last 3 lines are commented out and replaced with the echo.

1 Like

After echo this 3 lines, I have instant output to the screen. Thanks.

How to find the issue with database? Any suggestions?

This probably means it is not the database.
Look next at the mpdf library

I am not sure how to help further. You can try searching similar issues with the mpdf library.

2 Likes

Thanks for help, for now will stay with html output. When will have time, I will try to look more into mpdf library.