douwei7203 2016-04-25 13:22
浏览 354

Tcpdf使用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.

  • 写回答

1条回答 默认 最新

  • douyong5476 2016-04-25 13:46
    关注

    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);
    
    评论

报告相同问题?