Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'm using a multi-site setup where the (public) files directory for reach website is located at ../sites/example.com/files.
If I try to create a PDF of a node (using TCPDF) I get an error message:
TCPDF ERROR: [Image] Unable to get image: file:///<drupal base>/files/<path>/<filename>
for all images including the site logo. TCPDF seems to be looking in /files for images rather than the defined files directory.
A workaround for the logo is to place a dummy file in the /files directory, but any nodes containing images produce an error message when trying to produce a PDF.
Comments
Comment #1
jcnventura CreditAttribution: jcnventura commentedThe module currently tries to replace the base_url (i.e. http://www.example.com/base_path) with the realpath of (your document root + base_path). Which works fine in single-site installs :)
I've never tested a multi-site install, but I can't understand why the above seems to be dropping the 'sites/example.com' from the path. I'll try to setup a multi-install test to fix this.
Comment #2
ceme CreditAttribution: ceme commentedHi!
I've got the same problem on a single site installation because of my Apache configuration:
DOCUMENT_ROOT = /www/
base_path() = /test/ (eg. http://localhost/test)
But my Drupal install is in /www/test/web/*
So, when you concat DOCUMENT_ROOT and base_path(), it gives me /www/test/ that is not correct (missing the "web" directory in my case).
The problem seems to come from print/print_pdf/print_pdf.pages.inc, lines 123-125:
Here is my config in httpd.conf:
Thanks in advance for your help!
Cedric
Comment #3
ceme CreditAttribution: ceme commentedIn my case I resolved the above problem by changing the line 124 in print/print_pdf/print_pdf.pages.inc
from:
to:
I hope it can help...
Cedric
Comment #4
jcnventura CreditAttribution: jcnventura commentedThere's an extra '/' in the line above. Other than that, it seems to be a better solution indeed.
Comment #5
ceme CreditAttribution: ceme commentedHehe, you're right! I've added this slash because I thought dirname() was trailing the final slash. But I haven't seen yours ;-)
Thanks to add this code in your next release...
Cedric
Comment #6
jcnventura CreditAttribution: jcnventura commentedHi,
I've committed the patch in #3.
jmbarlow, can I ask you to try the latest dev in your multi-site?
João
Comment #7
jmbarlow CreditAttribution: jmbarlow commentedHere's my contrib:
In this example, the path to the logo file is: http://example.com/sites/example.com/files/logo.png
It's filename is /home/account/public_html/sites/example.com/files/logo.png
Using the original $replacement definition, the value passed (and error) are:
TCPDF ERROR: [Image] Unable to get image: file:///home/account/public_html/./files/logo.png
Using the new $replacement [without the extra slash], the value passed (and error) are:
TCPDF ERROR: [Image] Unable to get image: file:///home/account/public_html/./files/logo.png
Using the same method as from Line 120 above for Private Filesystems, I get:
TCPDF ERROR: [Image] Unable to get image: file:///home/account/public_html/sites/example.com/files/./files/logo.png
which is pretty close. I can fiddle things with .htaccess files and similar to make it work, but someone else might get caught out.
preg_replace() is turning $2 in the $replacement string into "./files/logo.png". I'm dreadful at writing regular expression, but if you can find a way to spit out the filename and higher level directories without the ./files on the front, then you can concatenate that string with the realpath() of the files directory and we're good to go. I think this might work regardless of Private or Public storage as well.
James
Comment #8
jcnventura CreditAttribution: jcnventura commentedUnfortunately, the solution to the private files (file_directory_path()) is not feasible for the general case as images can be included from modules/themes, etc which are not located in the files directory.
I'll need to create a multi-site test to figure this out..
The problem seems indeed to be in $2, as that should be sites/example.com/files/logo.png and not './files/logo.png'..
João
Comment #9
jmbarlow CreditAttribution: jmbarlow commentedI can arrange a test environment with a few sites in it if you need one.
Comment #10
jcnventura CreditAttribution: jcnventura commentedHi,
I think this may have been caused by my removal of a call to init_theme() a few weeks ago. Can you please add a call to init_theme() at the beginning of the _print_var_generator() function in print.pages.inc?
This is caused by themes that rely on path_to_theme() instead of drupal_get_path("theme", __theme_name__).
I've added the init_theme call back to CVS, but the next dev version may take some hours to generate.
João
Comment #11
jmbarlow CreditAttribution: jmbarlow commentedI don't see a print_var_generator() function in the print.pages.inc in 6.x-1.11
Comment #12
jcnventura CreditAttribution: jcnventura commentedIt's around line 152.
Comment #13
jcnventura CreditAttribution: jcnventura commentedAnyway, try the 6.x-1.12 version which already has the call to init_theme added.
Comment #14
jmbarlow CreditAttribution: jmbarlow commentedNo joy on 6.x-1.12, unfortunately.
The error message from TCPDF is:
TCPDF ERROR: [Image] Unable to get image: file:///home/account/public_html/./files/logo.png
where the actual multisite path is
file:///home/account/public_html/sites/example.com/files/logo.png
Comment #15
jcnventura CreditAttribution: jcnventura commentedComment #16
kirie CreditAttribution: kirie commentedI'm having truble with TCPDF for a multisite as well. The error displayed is like this:
TCPDF ERROR: [Image] No such file or directory in file:///home/admin/domains/multisite.example.com/public_html/sites/subsite.com/files/fields/field_image/news/2010/image.jpg?1287688840
What's strange is that the image is actually present in the that location. The permissions on the file is:
-rw-rw-r-- 1 apache apache
- does that have anything to do with it?As a side note, the actual
files/
directory is symlinked from another place in the directory tree.Comment #17
pedropablo CreditAttribution: pedropablo commentedHello all. After dealing with this strange bug, I have found that the problem resides in the function _print_pdf_file_access_images()
When this function try to get the complete file:// url for the file, it does not remove the query string, thus resulting in the local file not being available to tcpdf (as tcpdf does not understands about query strings).
I don't know what's wrong with the regular expression defined in variable $pattern
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
too much for my limited experience with regexp :-))
However, substituting that $pattern expression with this simpler one (used in a previous version of the module)
$pattern = "!(<img\s[^>]*?src\s*?=.*?)%3F\d+([^>]*?>)!is";
Works for me.
BTW, most error messages posted in this thread have three (3) slashes after file:
file:///
. These are added by the $replacement variable in _print_pdf_file_access_images() function. Although it shouldn't be much of a problem: I have modified the numbre of slashes, and it is only reflected when there are other error, as changing this does not results in errors once the $pattern variable is fixed (very strange, indeed)Comment #18
powery CreditAttribution: powery commentedI have the same issue:
TCPDF ERROR: [Image] Unable to get image: /home/users/rad/blabla.cz/web/sites/all/libraries/tcpdf/images/file:///home/users/rad/blabla.cz/web/sites/default/files/logo.png
The latest dev version has the same problem.
Comment #19
pinoguin CreditAttribution: pinoguin commentedEven from a non-multi-site I'm still getting the same error
Comment #20
iamjon CreditAttribution: iamjon commentedI'm also having the problem with a multisite/multilang install.
Comment #21
jcnventura CreditAttribution: jcnventura commentedI'm planning to add an option to not use local file access, which may or may not fix the problem.
The major problem with developing a fix for this is the extra time in setting up a multi-site test.
Comment #22
iamjon CreditAttribution: iamjon commentedjcnventura
if I have a multisite test running, how can I help?
Comment #23
jcnventura CreditAttribution: jcnventura commented@iamjon: look at the lines surrounding the line with:
$replacement = '$1file://'. dirname($_SERVER['SCRIPT_FILENAME']).'/' .'/$2';
Maybe you can PM to me the value of the $html, $pattern and $replacement going into those lines.. Also, I'll need to know the real path in the server where one those files can be found.. They should be similar to value of $replacement.
Comment #24
jcnventura CreditAttribution: jcnventura commentedThe latest version of the module (6.x-1.14) is by default configured to access images using the HTTP access. (see #1158678: Print module does not preprocess ImageCache Formats)
It can be configured back to the old setting, if required..