Problem generating PDF with mPDF in hosting

Asked

Viewed 1,258 times

-4

The following is, I installed mPDF via Composer to develop the localhost project (on the PC). Everything works normally on the machine. I uploaded the VENDOR folder to the hosting, but it’s not generating the PDF. Could someone give me a hint as to what might be going on? The PHP version is 7.2.7.

Error in server log file:

[01-Apr-2019 22:19:44 America/Sao_Paulo] PHP Deprecated:  Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
[01-Apr-2019 22:19:46 America/Sao_Paulo] PHP Fatal error:  Uncaught exception 'Mpdf\MpdfException' with message 'Unable to set PDF file protection, CSPRNG Functions are not available. Use paragonie/random_compat polyfill or upgrade to PHP 7.' in /home/transpomk/public_html/novo-website/sistema/libs/php/vendor/mpdf/mpdf/src/Pdf/Protection/UniqidGenerator.php:11
Stack trace:
#0 /home/transpomk/public_html/novo-website/sistema/libs/php/vendor/mpdf/mpdf/src/ServiceFactory.php(68): Mpdf\Pdf\Protection\UniqidGenerator->__construct()
#1 /home/transpomk/public_html/novo-website/sistema/libs/php/vendor/mpdf/mpdf/src/Mpdf.php(1033): Mpdf\ServiceFactory->getServices(Object(Mpdf\Mpdf), Object(Psr\Log\NullLogger), Array, 0, Object(Mpdf\Language\LanguageToFont), Object(Mpdf\Language\ScriptToLanguage), NULL, NULL, NULL, NULL)
#2 /home/transpomk/public_html/novo-website/sistema/model/CreatePDF_01.php(105): Mpdf\Mpdf->__construct(Array)
#3 /home/transpomk/public_html/novo-website/sistema/control/view-pdf.php(24): CreatePDF_01->solicitacaoPDF(Array)
#4 {main}
  thrown in /home/transpomk/public_html/novo-website/sistema/libs/php/vendor/mpdf/mpdf/src/Pdf/Protection/UniqidGenerator.php on line 11
  • 1

    Access your server log file and see what the error message is.

  • Error in the temporary folder permissions, error in the permissions of the class fonts dump directory, permission error in the class cache, error in your code, anyway, can be anything...

  • Regarding the code could be a matter of paths and directories, however, I went up the pasture in the same localhost sequence. Permissions may even be...

  • The error itself already accuses lack of functions CSPRNG. And it even suggests a polyfill or upgrade to PHP 7: "Uncaught Exception 'Mpdf Mpdfexception' with message 'Unable to set PDF file Protection, CSPRNG Functions are not available. Use paragonie/random_compat polyfill or upgrade to PHP 7.' in"

1 answer

3


The solution is in LOG itself:

Unable to set PDF file Protection, CSPRNG Functions are not available. Use paragonie/random_compat polyfill or upgrade to PHP 7

If CSPRNG functions are not available it is because it is using PHP5 and not PHP7 on the server, these functions only exist in 7

Solutions:

  1. Switch to PHP7 if hosting allows
  2. Use this library that adds the features in PHP5: https://github.com/paragonie/random_compat

To install the paragonie/random_compat should be done on the local machine, use the Composer inside the folder of your project in Windows:

composer require paragonie/random_compat:\<9.99

The :\<9.99 is the unique support for PHP5, if you use the command like this:

composer require paragonie/random_compat:\>=2

It will support PHP5 but can also be used with specific libs for PHP7, in your case it does not seem to be the need.

  • Guilherme, the PHP version of the hosting is 7.2.7

  • @Renatodamazio if it is then have a serious BUG in your hosting, do so, create a file called info.php in his public_html, within that file add just this <?php phpinfo(); ?>, save and then access your hosting address so http://meusite.com.br/info.php and see which version of PHP, remember, a hosting can offer several versions

  • really you were right. the version that was displayed is PHP Version 5.6.40. What would be the best option for me to solve this problem?

  • @Renatodamazio if hosting allows you to migrate to PHP7, usually has to change the panel if you do not use the composer require paragonie/random_compat:\<9.99 and then upload the project back to your hosting.

  • posted another bug that is now. However, I upgraded to PHP7 on the server.

  • @Renatodamazio you want to display the PDF on the screen or want to save in a file if you want to display then have some text or HTML mixed ai in the middle or top of the document that is causing the failure.

  • 1

    solved! It was exactly what you mentioned above. There was HTML code mixed with PHP. Just highlighting one thing too: After I removed the HTML tags and left only the PHP tags, it still gave error in line 1 of the file, then I remembered to read in a search I did, about removing all spaces before the opening of the PHP tag, I did that and now it’s working perfectly. Thank you so much for your help!

  • @Renatodamazio for nothing, if you can mark the answer as the correct one. Thank you

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.