Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/

Tags:

php

tcpdf

I have a website that is generating a PDF file based from data.

I tried it in a free webhost and it is ok but when i upload it to my server i get this error:

TCPDF ERROR: Can't open image file: /var/www/html/tcpdf/cache/mska_1d34cb1ba2c1951624fbccb7556c6d1d

in the cache folder the mska_1d34cb1ba2c1951624fbccb7556c6d1d doesnt exist in the folder.

like image 258
Bert Avatar asked May 28 '12 09:05

Bert


People also ask

Why are my images not showing up in TCPDF?

One cause is that folders inside tcpdf has no permissions of write and read. make sure the folder for cache and images has 644 or 755 (recommended) permission. these permission is very important because there is a process when generating pdf it write something is the cache or read into images.

How do I pass an HTML image to TCPDF?

It can be passed to TCPDF using an @ in the image's src-attribute, like so: An img-tag in HTML takes a BASE64 encoded string, unlike the Image () function, which takes unencoded data. I don't know if this is even documented, I found this by reading the code (tcpdf.php, line 18824 pp):

What is TCPDF?

Open Source PHP class for generating PDF documents. Started in 2002, TCPDF is now one of the world's most active Open Source projects, used daily by millions of users and included in thousands of CMS and Web applications. Check the examples...

How do I change the path of an image in TCPDF?

TCPDF is using $_SERVER ['DOCUMENT_ROOT'] as a root directory of all your images, and builds their absolute paths in relation to it. You can change it either in $_SERVER or with this PHP constant: K_PATH_MAIN: Show activity on this post. I use image data instead of paths. It can be passed to TCPDF using an @ in the image's src-attribute, like so:


2 Answers

I got the answer now.

For all who will be able to encounter this problem these are the possible solution.

One cause is that folders inside tcpdf has no permissions of write and read. make sure the folder for cache and images has 644 or 755 (recommended) permission. these permission is very important because there is a process when generating pdf it write something is the cache or read into images.

another cause is that tcpdf does not accept png file or with transparent images. my solution was to make the image into a jpeg and apply a white background for it. so avoid png with transparent.

hope it helped.

like image 80
Bert Avatar answered Sep 24 '22 13:09

Bert


In Ubuntu this error was fixed by setting 777 permissions on the tcpdf/cache/ folder:

chmod 777 cache

I tried with 755 or 775 and did not work.

like image 32
Edgar Ortega Avatar answered Sep 25 '22 13:09

Edgar Ortega