Hi,
i use Printer, e-mail and PDF versions(tcpdf) to generate pdf file, the pdf file generate very well in my localhost, but when i copy it to my sandbox, it won't appear. it show a error message like this

"TCPDF ERROR: [Image] No such file or directory in http://www.example.com/sites/all/themes/example/logo.png"

i have double checked the path, logo.png is still there, i don't do something wrong i guess

i tried
http://drupal.org/node/314521 and http://drupal.org/node/337798 but it didn't help me to solve this problem

can someone help me for this problem?

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Your server is probably not authorized to access itself..

paradise7777’s picture

Status: Postponed (maintainer needs more info) » Active

hi João,

i tried to authorized it, i use chmod 777 but nothing changed,
any other solution João?

jcnventura’s picture

It's not the file access rights. The Web server is unable somehow to access an URL in itself.. It can be an apache setting or DNS configuration, or a firewall setting.

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)
paradise7777’s picture

Status: Postponed (maintainer needs more info) » Active

after i try what you said and then i try the printer friendly, i used http://www.example.com/?q=print/book/export/html/225 the display for printer friendly appear, but when i want to display the pdf version it turn into the same error again, i used http://www.example.com/?q=printpdf/book/export/html/225 is it the TCPDF?
what shoud i do to handle this?

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

When you (your browser) accesses the print-friendly page, it's coming from outside the server.

When TCPDF accesses the page, it's coming from inside the server. Check your logs to see when/why it's denying access to that file.

João

paradise7777’s picture

Status: Postponed (maintainer needs more info) » Active

getimagesize(http://www.example.com/logo.png) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 401 Authorization Required in /hermes/web10/b930/hoc.example/example-projects/example/sites/all/modules/print/print_pdf/print_pdf.pages.inc on line 393.

in line 393 : $size = getimagesize($logo);

i have change the $logo into :

$size = getimagesize('http://www.example.com/sites/all/themes/example/logo.png');

but it'doesn't effect. and then i tried to use cURL,

i put this function in print_pdf.pages.inc

function remote_filesize ($url, $user='web', $pass='user') {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");

$data = curl_exec($ch);
curl_close($ch);

$filename = "temp." . time();

$fp = @fopen($filename, "w+");
fwrite($fp, $data);
fclose($fp);

$info = getimagesize($filename);

@unlink($filename);

return $info;
}

and then i put this code inside the print_pdf.pages.inc
i replace $size = getimagesize($logo); with
$size = remote_filesize("http://".$_SERVER['HTTP_HOST']."/logo.png);

but still error, what should i do?

jcnventura’s picture

Status: Active » Closed (fixed)

I have repeated this too many times: Your server is not authorized to access itself. Figure it out in your server/network/firewall configuration.

There's nothing the module can do to change that. I am closing this, as I'd prefer if you stopped wasting my time. Please read what I have written 3-4 times now and start figuring out how to solve your problem.

João

paradise7777’s picture

okay, João

thanks for your help and i'm sorry to wasting your time

celideo’s picture

Just add:

allow_url_fopen = On;
allow_url_include = On;

to php.ini... not so hard.

mdriess’s picture

Maybe this comment is important for those gyus who do have still the problem: If you have an Apache authentification (e.g. because you don't want to let see the content before it is ready) this behaviour is normal and cause on the authentification.

kndr’s picture

Thanks mdriess! "this behaviour is normal and cause on the authentification" - exactly!

jordannoel’s picture

Is there any solution for drupal 6.15?

timezero’s picture

adding

allow_url_fopen = On;
allow_url_include = On;

to php.ini in the drupal folder (create it if it's no there) solved it for me.

Jonasvh’s picture

i had the same problem because the url of my site was without WWW
When i go to my site with WWW on the front of the URL, everthing worked fine.

jcnventura’s picture

I guess this issue is also related to #726082: Looks like there's an undocumented dependency in the print_pdf module on allow_url_fopen setting. I've tried to remove the dependency on allow_url_fopen, in the current module versions, so TCPDF may now work slightly better for some of you.

sz___g’s picture

Maybe wrong path calculation in case of pictures. Try to comment in tcpdf.php like this:

case 'img': {
if(isset($attr['src'])) {
// replace relative path with real server path
if ($attr['src'][0] == '/') {
$attr['src'] = $_SERVER['DOCUMENT_ROOT'].$attr['src'];
}

comment this line -----> // $attr['src'] = str_replace(K_PATH_URL, K_PATH_MAIN, $attr['src']);

if(!isset($attr['width'])) {

This helps the problem below:

Warning: fopen(somewhere//libraries/something.png) [function.fopen]: failed to open stream: No such file or directory in /libraries/tcpdf/tcpdf.php on line 3717
TCPDF error: Can't open image file: somewhere//libraries/something.png