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/
Mohammedshafeek C S
  • 1,916
  • 2
  • 16
  • 26