0

i've used mpdf for dynamic pdf generation, PDF is working fine but in online server when i'm trying to preview the pdf in browser or download it to my pc , it shows "Unable to Load Pdf". I've also tried to check it into editor, i've not found any curropted error symbol.

Ob_clean(); // not working for me

here is my code:-

<?php         
        require_once 'vendor/autoload.php';

        $mpdf = new \Mpdf\Mpdf();

        $mpdf->WriteHTML('

            <table style="text-align:center; background: '.$color1.'; color: '.$color2.'; width: 100%">
                <tr>
                    <td style="width: 50%; font-size: 45px;">
                        HI,
                    </td>
                </tr>
                <tr>
                    <td style="width: 100%;">
                        <table style="width: 80%; border: 4px solid #fff;">
                            <tr>
                                <td>I am</td>
                            </tr>
                            <tr>
                                <td style="font-size: 32px;">'.$_POST['input1'].'</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td style="width: 100%;">
                        <table>
                            <tr>
                                <td style="font-size: 20px;">'.$_POST['input2'].'</td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>



        ');
        $file_name = "resume.pdf";

        $mpdf->Output($file_name, 'I');
    }

?>
Hemant
  • 1
  • 2

1 Answers1

0

Mpdf needs PHP 5.4+ Make sure that you provide the following required PHP modules:

  • gd
  • mbstring

If not for example in Linux we can install by using following two commands(change 7.0 to your server's PHP version)

sudo apt-get install php7.0-gd
sudo apt-get install php7.0-mbstring

IMPORTANT : Also check the group where resume.pdf saving is www-data and it has write permission there recursively. We can add it by following commands

sudo chgrp -R www-data folderpathhere/
sudo chmod -R g+w folderpathhere/
Mohammed Shafeek
  • 1,846
  • 2
  • 13
  • 24
  • both mbstring & gd extensions are enabled and my php version is also 7.1. i'm trying to fix this for 3 days , no errors is showing. I've also checked it in editor. – Hemant Oct 02 '19 at 05:36
  • What about file permissions? – Mohammed Shafeek Oct 02 '19 at 05:50
  • Open Apache error log..and check latest errors..it will mostly inside /var/log/apache2/ folder – Mohammed Shafeek Oct 02 '19 at 05:52
  • here is the error in error log- PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 400556032 bytes) in Unknown on line 0 – Hemant Oct 02 '19 at 06:33
  • Check error time too...if it's because pdf solve by following https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte/415818 – Mohammed Shafeek Oct 02 '19 at 06:38
  • Will `sudo apt-get install php7.0-gd` work on Fedora or Windows? – brombeer Oct 02 '19 at 06:44
  • i've updated the memory size to unlimited. but not working at all – Hemant Oct 02 '19 at 06:57
  • [Wed Oct 02 03:10:02.427634 2019] [core:crit] [pid 16822] (13)Permission denied: [client 03.174.05.106:48928] AH00529: /home/user/public_html/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/home/user/public_html/' is executable – Hemant Oct 02 '19 at 07:03
  • sudo chmod 644 /home/user/public_html/.htaccess sudo chmod 755 /home/user/public_html/ – Mohammed Shafeek Oct 02 '19 at 07:23
  • Did u give write permission where resume.pdf is generating? – Mohammed Shafeek Oct 02 '19 at 07:29