Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert image in pdf in php using mpdf

Here,below is my code for converting an image into pdf using mpdf. $html contains upload/tulips.jpg But,when the function executes the pdf file created and an image icon shows there with the location upload/tulips.pdf. Kindly tell me why this is happening because no bug is coming.

   private function ConvertImageToPdf($inputPath,$outputPath)
            { 
                $mpdf=new mPDF();
                $html='<img src='.$inputPath.'/>';
                $mpdf->WriteHTML($html);
                $mpdf->Output($outputPath.".pdf",'F');
                $mpdf->debug = true;

            }
like image 545
Navya Avatar asked Dec 09 '22 13:12

Navya


2 Answers

$html='<img src="'.$inputPath.'"/>';

eg "" around image-path, and you should be good (if the image exists)

In the mPDF-package /examples there is a example04_images.php you can try out.

PS : You should set $mpdf->debug = true before $mpdf->Output()

like image 133
davidkonrad Avatar answered Dec 11 '22 02:12

davidkonrad


its the comma problem

$html='<img src="'.$inputPath.'"/>';
like image 42
Navya Avatar answered Dec 11 '22 02:12

Navya