Getting a local image in PDF using DOMPDF - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, October 22, 2023

Getting a local image in PDF using DOMPDF

I am new to PHP and trying to build a little project for my assignment.

I am trying to convert some HTML to a PDF using PHP (DOMPDF package). The HTML does contain some tags to output some images that are locally stored within the this project's folder.

I am currently getting "Image not found or type unknown" error, which I have seen is quite common when trying to do this.

I have done some research and experimented with quite a few different things, however I do not seem to be getting anywhere unfortunately.

Does anyone know what I might be doing wrong?

Just a little snippet from my project:

index.php

<?php 

require_once 'packages/dompdf/autoload.inc.php'; 

use Dompdf\Dompdf;

$dompdf = new Dompdf();

$dompdf->loadHtml("<img src='photo.jpeg'>");

$dompdf->setPaper('A4', 'portrait'); 
 
$dompdf->render(); 

$dompdf->stream("test-pdf", array("Attachment" => 0));

?>

The image is stored in the same directory as the index.php file. I am using XAMPP as a development environment.

Hope this is described correctly. Thanks everyone and appreciate the support!



source https://stackoverflow.com/questions/77337259/getting-a-local-image-in-pdf-using-dompdf

No comments:

Post a Comment