Hi,

thanks for excellent module. International characters are now perfect with TCPDF but I receive error:

TCPDF error: Missing or incorrect image file:

In ommited part there's a "system/files/images" path but files (and thus images) are residing in private folder so they cannot be accessed directly via web. How to resolve this without changing to public method in Drupal configuration?

Sergej

Comments

jcnventura’s picture

Hi,

The problem is that Drupal simply 'obscures' a real path (usually sites/default/files) by a virtual path (system/files). TCPDF expects to be able to find it in a path relative to the install path of Drupal. Since this path doesn't exist, TCPDF doesn't know where to find it..

A simple solution seems to be to replace all private paths back to the real path..

I am taking a look at it.

João

jcnventura’s picture

Status: Active » Fixed

Hi,

I have committed a fix for this, that works, as long as the private path is still relative to the Drupal installation path.

João

SergioGuru’s picture

Well,

great. I believe it works but then how to hide private files so they are not directly accessible from browser? Do you recommend solutions like

http://drupal.org/node/189239 ?

Anyway, thanks for update. I'll change to public files for a while (not much content) but TCPDF with private files is really best combination.

jcnventura’s picture

Status: Fixed » Postponed

Hi,

The problem of making the images truly private is that you either:

a) can see them in a browser (so their URL contains the server root URL, and Drupal's PHP handles the logic of making them accessible). Since TCPDF doesn't know this logic, the files are not be accessible to TCDPF.

b) provide the real internal path in the page, where TCPDF can see them nicely. However the images won't show in the browser.

So the only viable solution currently is to make the private path relative to the

There's also c:

c) Make this module rewrite the image URLs to contain the real path of the image file wherever that may be in the file system.

This last one is not so complicated, but I am focusing on other stuff at the moment.

João

jcnventura’s picture

Status: Postponed » Fixed

Hi.

I have just committed some code which changes the img path to a file:// URL that can be used to access the file wherever it is in the filesystem. It doesn't work for dompdf (it seems that it can't handle the file protocol). For TCPDF, this enables it to access the private files wherever they are in the filesystem.

João

adaven’s picture

Status: Fixed » Needs work

Hi,

First of all great module, very useful! I've had a go with your latest patch to fix private files, and there are two problems I've come across.

  1. If clearn URLs aren't being used then the pattern on line 45 of print_pdf.pages.inc doesn't seem to work. My regex is a bit rusty, so I can't figure out why at the moment.
  2. If the file directory is relative i.e. "../files", then your replacement pattern on line 46 of print_pdf.pages.inc won't work.

Obviously the first problem can be fixed relatively easily, but the second might be a bit harder.

adaven’s picture

Ok, I dug out my old regex reference manual. This seems to work for both clean and unclean urls

in print_pdf.pages.inc:
<?php
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(\?q=)?system/files(/[^>]*?>)!is";
$replacement = '$1file://'. file_directory_path() .'$3';
?>

I just added a (\?q=)? optional sub-pattern, and replaced $2 with $3 in $replacement.

jcnventura’s picture

Status: Needs work » Fixed

I committed some similar code to the one you indicated that should handle the unclean URLs.

João

adaven’s picture

There's still the issue of relative filepaths, but this is a separate issue. I'll create a new issue

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.