开发者

TCPDF ERROR: [Image] Unable to get image

I'm using TCPDF with Drupal's print module to generate PDF of articles, & ending up with following error message when I click the link to generate PDF:

TCPDF ERROR: [Image] Unable to get image: http://localhost/pathToDrupal/themes/bartik/logo.png

The Image exists in the location specifi开发者_如何学运维ed. I tried applying:

allow_url_fopen = On;
allow_url_include = On;

in php.ini but that could not resolve the problem.

Please care to help :(


Apparently the "fopen"-wrappers are not used by TCPDF.

If you supply the URL of an image, TCPDF tries to download it with cURL into the "cache"-directory where your TCPDF-installation is stored (you have to check what the K_PATH_CACHE-constant contains to be sure).

So I guess you have to have write permissions in this directory that the magic works. Also you need cURL enabled.


We had problems with the way connections were handled in our linux "example.com" server. So this lead us to try on the server:

curl -v http://www.example.com/image.jpg

Whenever TCPDF tried to download an image with curl, the image was not found, nevertheless, we could view the image by just opening it directly in the browser (e.g. http://www.example.com/image.jpg).

We solved the problem by setting the example.com VirtualHost to accept 127.0.0.1 connections and adding the line "127.0.0.1 example.com" to /etc/hosts.


Just use the image path as "images/your_image.png" instead of "http://yourdomain.com/images/your_image.png" in the PDF html.


I've found that TCPDF would throw the Unable to get Image: error when the src was an absolute link. Just changing to a relative link would successfully create the PDF.


I had this problem on a staging server where the docroot of the site was protected by an .htaccess file (to prevent search engine indexing and other confusions)

tcpdf uses curl to fetch the image and it gives this error if it cannot access the file.

To solve it, I added a rule to .htaccess to allow requests from the webserver

Allow from 123.45.6.7.8


Try to add path by current working dir.

$img = getcwd().'/web/bundles/_bundlename_/img/logo.png';


$pdf->Image($base_url.'/'.$node->field_loc_images[0]['filepath'] ,30, 40, 75, 113, 'JPG', '', '', true, 300, '');


In your font unicode problems you need to put this syntax code:

// set font
$fontname = $pdf->addTTFfont('../your path here/sampletruetype.ttf', 'TrueTypeUnicode', '', 32);

$pdf->SetFont($fontname, '', <font size value here>);

put it before you add the page...


In drupal be sure to include the tcpdf library in your function and not at the top of your module file or you will get this error.


try this also

foreach($node->field_loc_images as $key=> $s)
{
    $pdf->Image($base_url.'/'.$s['filepath'], $x, $y, $w, $h, 'JPG', '', '', false, 300, '', false, false, 0, $fitbox, false, false);
}


To expand on the error. It also seems to fail with base64 embedded images. This is a big problem for me right now.


After I upgraded PHP 5.5 to 5.6, I lost hours because of an image error,

I found the solution here from @caligari (a comment on the accepted answer) and it fixed the problem for me:

install CURL like this:

apt-get install php5-curl && /etc/init.d/apache2 restart. 


In my case I tried to

curl -v http://www.example.com/image.jpg

and the "curl: (60) server certificate verification failed." was shown. So it was simply a certificate issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜