user2233326
user2233326

Reputation: 33

Tcpdf displaying image using url

I am using tcpdf to generate PDF report. I want to print images on the PDF report but I have the URL for the images, example https://myserver.com/media/4410/field.jpg

When I use this in Image() function of tcpdf. It does not show any image. The images are not on the same server where I am running my php script to generate PDF reports. How can I access these images and display them on the PDF. Why the URL is not working. Please suggest. What am I doing wrong.

Upvotes: 0

Views: 6220

Answers (1)

Peter
Peter

Reputation: 9113

You could store the image locally in your temp folder:

$image = @file_get_contents('http://www.example.com/image.jpg');

if ($image != '') {
    $filename = uniqid.'.jpg';
    file_put_contents('/tmp/'.$filename, $image);
}

// You can now insert your image using the $filename variable
$pdf->image('/tmp/'.$filename);

Upvotes: 1

Related Questions