Hi there,

The module is working fine if drupal file system is set to public. When I try to set the file system to private, I get the following error :

TCPDF ERROR: [Image] Unable to get image: http://xxxxxx.com/system/files/styles/large/private/test/main-picture/ma...

I can access the picture with the direct link but TCPDF seems to have some problems with it.

I tried :
- To modify php.ini (allow_url_fopen = On; allow_url_include = On;)
- To modify the tcpdf cache folder permissions to 777
- To update the tcpdf config file following this post instructions http://drupal.org/node/1220408#comment-5732246

Does anybody has the pictures displaying in there pdf view while being in private file system mode ?
Any idea what I could try ?

Thanks,
Clem

Drupal version : 7.12
Views PDF version : 7.x-1.x-dev

Comments

No ideas so far ? Anybody could just confirm the problem ? Or not ?

Having similar isue. I have a QR-code (generated with the barcode module) but when I try to generate the pdf with the QR-code image (.png) in it I get:
TCPDF ERROR: [Image] Unable to get image: http://localhost:8080/drupac/sites/default/files/barcodes/0a0cd8c000bc7b...

Having a similar issue when trying to add a .PNG to a PDF.

TCPDF ERROR: [Image] Unable to get image: http://somesite.com/sites/default/files/some_image(14).png?1334900150

Have tried changing permissions on files directory. I do not think that this is a permissions issue.

This happens if the anonymous users don't have the permission to view the images. The HTML given to the TCPDF library has the image URLs in relative format "/path/to/image".

On line 23092 of tcpdf.php:

// replace relative path with real server path
if (($tag['attribute']['src'][0] == '/') AND !empty($_SERVER['DOCUMENT_ROOT']) AND ($_SERVER['DOCUMENT_ROOT'] != '/')) {

The URLs are converted to absolute URLs, and then fetched with cURL. Since cURL is basically an anonymous user, it can't get the images.

I'm working on a solution.

EDIT: Also, you need to solve this issue first: http://drupal.org/node/1420812 . If your images are orphaned, they can't be downloaded by anyone. This should be obvious even before trying to generate the PDF, though.

Status:Active» Needs review
StatusFileSize
new2.65 KB

And here's the patch. It is a bit hacky, since it uses HTTP-requests to check for access to the file in question. Nonetheless, it works for me.

And here's another version that can deal with absolute URLs in the src-attribute.

Hi,
I'm experiencing this issue, but even with Drupal set to public file system. (Views_PDF works on my local dev box but not on our VPS and the TDPDF examples work on the VPS).

The error:
TCPDF ERROR: [Image] Unable to get image: http://kb.myvps.net/sites/default/files/styles/large/public/images/IMG_3...

However I can view this file directly in the browser.

Following Clem's lead I've:
- Modified php.ini (allow_url_fopen = On; allow_url_include = On;)
- CHMOD the tcpdf cache folder permissions to 777
- Updated tcpdf_config.php to point to my sites/default/files folder.

I tried applying both patches, however getting and error:

patch < views_pdf-issue_with_private_files-1509534-5.patch
patching file views_pdf_template.php
Hunk #1 FAILED at 398.
1 out of 1 hunk FAILED -- saving rejects to file views_pdf_template.php.rej

Suggestions anyone?

Thanks in advance,

Chris

Same problem. Following here...

Does anyone know if this BUG is being reviewed ? We have experienced this problem on our site.

Have you tried applying the patches with "git apply PATCHFILENAME"?

For those who are using 7.x-1.0-rc1, not dev version - I created a patch. Just to not duplicate issue. I don't forget about write permission to sites/all/libraries/tcpdf/cache

Here are new patches, with a bug fix that has to do with multilingual URLs that have language prefixes in them.

Image URLs starting with for example en/system/files* instead of system/files* will fail with the previous patches.

I am trying to apply these patches. Am using rc1 at the moment and I get the following error "The patch cannot be applied in the selected context". What could I be doing wrong?

@nandwabee - read the Drupal documentation on applying patches:

http://drupal.org/patch/apply
http://drupal.org/node/60116

etc.

I'm having this issue, but can't get this patch to work.

Do I need to take any other steps other than applying the patch (there is mention of CHMODDING some folders above)

Did you notice this in #4 ?

"EDIT: Also, you need to solve this issue first: http://drupal.org/node/1420812 . If your images are orphaned, they can't be downloaded by anyone. This should be obvious even before trying to generate the PDF, though."

I'm not using file entity module as i'm using media 7.x-1.0.

This worked on my local machine, but when i uploaded to a hosted server, I got the error.

The error message mentioned in the original post? ("Unable to get image...")

The TCPDF library uses, by default, a cache directory in the library directory (which isn't the right place at all for a cache directory, but that's a different story).

So, the directory at /sites/all/libraries/tcpdf/cache should be writable by the web server. Is it?

Thanks for your help @firebird

Yes its the same issue - TCPDF ERROR: [Image] Unable to get image: [mysite]/sites/default/files/styles/journal/public/DSC05246.JPG

And the tcpdf cache folder is writable by the server. In fact it is 777 at the moment.

BUT, looking at the address above in my error, that file does not exist.

What would cause that - do you know?

EDIT: the file was there, i hadn't refreshed - DOH.

So I have the original issue, despite having patched the module.

Is this directory there and writable? [mysite]/sites/default/files/styles/journal/public/

@firebird
I've applied the patch (rc1) but I'm still getting TCPDF ERROR: [Image] Unable to get image:…
When I check the logs, it says the user was anonymous. Is the patch supposed to allow TCPDF to access the files as the current user? If so, that doesn't seem to be happening for me.

@firebird

Apologies for slow reply - *somehow* this just seemed to suddenly work....

Thanks for your help, I think it was a permission problem.

I still have folders set to 777 though - do you know what they should be?

This issue was / is a complete pain in the ass to debug. I saw the same error messages all of you are seeing several times, with different configurations and directory permissions. I'm afraid I can't really help you much more.

@vegansupreme: As to what the patch does: When generating the pdf, normally the TCPDF library uses cURL to fetch the images that it then adds to the pdf. If anonymous users don't have the permission to view the images, you'll get the error. The workaround is to load the images in Drupal with the logged in user, and base64-encoding the images in the document being sent to TCPDF, so it doesn't need to do the cURL requests.

In other words, this patch _only_ helps you if your problem is caused by your Drupal permissions set so that anonymous users can't see the images.

@gillarf: 777 is a bit too much. I'd recommend 775, with the owner / group of the directory set to your shell user / the web server user's group respectively. If your web server is running on your user account, 755 is enough.

@firebird thanks - much appreciated.

Can someone summarize the issue for me? Is there actually something to fix there?

I think #4 describes the problem. TCPDF accesses files as an anonymous user, so if anonymous user does not have permission to access the files, there is an error.

The patch worked for me.

@firebird should be able to explain better than I.

Ok, thanks, I'll try to see if I can commit it.

Hi,

I have tried patch #12 on Views pdf rc1 but that did not help.
My cache folder inside TCPDF has permissions 777.
I also set permissions to 777 from my sites/default/files, but that didn't help

I still get the error "TCPDF ERROR: [Image] Unable to get image: .... sites/all/libraries/tcpdf/cache/...."

Maxplus

What about the permissions for the actual file? Did you refresh the cache?

Hi maxplus!

I created a patch which changes the cache directory to solve this problem. Mybe it could be useful for you also. See here - http://drupal.org/node/1220408#comment-7096938

Hi agnese.stelce,

thanks for the effort but I really need to use the rc1 version of views pdf because I need the php fields to create columns.
The patch doesn't work on the rc1 version, maybe I should try to make the changes manually?

yes, patch is against 7.x-1.0 but you can try those changes manually - it should work also on rc1.

The patch that the comment #30 mention its done here #1220408: tcpdf is trying to write in /sites/all/libraries/tcpdf/cache I'll need more information

Priority:Major» Normal
Status:Needs review» Postponed (maintainer needs more info)
Issue tags:-image, -tcpdf+Needs steps to reproduce

Dear fellow Drupal enthusiasts,

I have set this issue to "Postponed (Maintainer needs more information)".

If not already done please add an issue summary and steps how to reproduce the problem.
And please read again, "Making an issue report".

Help about how to do this can be found on IRC and in the user groups.

After there is new information, please re-open the issue by changing the status to active.

--
This issue was edited with the help of Issue Helper

Issue summary:View changes

Adding php.ini modification

Issue summary:View changes
Status:Postponed (maintainer needs more info)» Closed (works as designed)

Please open a new issue if you still have this problem.