heyanshukla
heyanshukla

Reputation: 669

How to display an image in pdf file by virtual path of that image using tcpdf?

What I am trying to do is something like this:

I have my image at http://xyz.com/upload/image.jpg.

And I am trying to display it in a PDF generated at http://xyzsolution.com/mypdf.php. While generating PDF I am getting error as

TCPDF ERROR: [Image] Unable to get image: imagepath

My code to display image in PDF is as follows :

$this->Image('http://xyz.com/upload/image.jpg', 0, 0, 30, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);

Upvotes: 0

Views: 3111

Answers (2)

heyanshukla
heyanshukla

Reputation: 669

I have found the answer.

    $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $imgdata = file_get_contents('http://xyz.com/upload/image.jpg');

    $pdf->Image('@'.$imgdata, 175, 5, 30, '', '', '', 'T', false, 300, '', false, false, 0, false, false, false);

In above statement '@'preceeding $imgdata indicates that it is followed by an image data stream and not an image file name.

Upvotes: 2

rajmohan
rajmohan

Reputation: 1618

I think it is not possible... that image should be downloaded to your webhost, after that you can use the physical path.

Upvotes: 0

Related Questions