Pdf output broken for nodes with images
mfitch - July 31, 2006 - 16:10
| Project: | Pdfview |
| Version: | 4.7.x-1.1 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | duplicate |
Description
I've checked the tcpdf_config.pdf -
giving it absolute or relative paths -
this image exists in both:
modules/pdfview/tcpdf/images/misc
and in
/misc/
any ideas?

#1
It's the one shipped by Drupal (drupal/misc/arrow-asc.png).
What kind of node is involved?
#2
it's a php page generated by the tablemanager module
<?phpprint tablemanager_display(1, null, false, array('column'=>'10', 'start'=>'m') );
?>
that generates the html output:
Last Name
The html display of the page is fine however (the arrow graphic appears)
#3
Try to change this line in the tcpdf config file:
define ("K_PATH_IMAGES", K_PATH_MAIN."images/");make it point to the root of your Drupal installation, as an absolute path, it should fix it.
#4
still having the issue: : fopen(/misc/arrow-desc.png) [function.fopen]: failed to open stream: No such file or directory in /home/fitchinf/public_html/modules/pdfview/tcpdf/tcpdf.php on line 3056.
I have images under files/images - public_html/files/images
(misc was at the same level as drupal - public_html/misc - I copied those files to files/images/misc)
(I also copied arrow-asc.png to files/images just to see if it would help)
(the perms are 755 on the directories)
I tried
define ("K_PATH_IMAGES", K_PATH_MAIN."files/images/");
and
define ("K_PATH_IMAGES", K_PATH_MAIN."public_html/files/images/");
and
define define ("K_PATH_IMAGES", K_PATH_MAIN."/home/fitchinf/public_html/files/images/");
the pdfview module works in many other places on the site without embedded images but not when there are images.
#5
I committed a fix in the 4.7 version. Now it finds the image, but the output isn't good looking
#6
now I'm seeing a different error: FPDF error: Image file has no extension and no type was specified:
any ideas?
#7
I improved the image url/path filter ... check the latest 4.7 version and see if it works.
#8
Changed to a meaningful title
#9
I need someone to test this patch (see howto apply patches)
You will need to set the value of K_PATH_IMAGES inside the tcpdf_config.php file to the root of your Drupal installation, for example:
define ("K_PATH_IMAGES", "/var/www/drupal/");#10
I went ahead and committed it
#11
#12
I have been having the same problem with the new version ($Id: pdfview.module,v 1.28.2.9 2006/11/13 23:34:53 egonbianchet Exp $) of this module. It was producing an fopen error because it couldn't find the file.
I had a look at the changed in the patch committed above on november 3rd (which was rolled into the version i downloaded).
function _pdfview_rewrite_image_url($matches = array()) {$path = $matches[0];
$path = str_replace($GLOBALS['base_url'].'/', '', $path);
$path = str_replace(base_path(), '', $path);
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
$q = variable_get('clean_url', 0) ? '' : '?q=';
$path = str_replace($q.'system/', '', $path);
}
return $path;
}
The problem is that my base_path() function returns only "/", so this line was converting paths like "misc/feed.png" to "miscfeed.png" which obviously doesnt exist.
$path = str_replace(base_path(), '', $path);I just commented out that line of code, and it seems to be working correctly now.
#13
UPDATE: sorry, my code above was not entirely correct. I had to add this line of code
if (substr ($path, 0 , 1) == "/") $path = substr ($path, 1);So the entire function should look like this:
function _pdfview_rewrite_image_url($matches = array()) {$path = $matches[0];
$path = str_replace($GLOBALS['base_url'].'/', '', $path);
if (substr ($path, 0 , 1) == "/") $path = substr ($path, 1);
//$path = str_replace(base_path(), '', $path);
if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
$q = variable_get('clean_url', 0) ? '' : '?q=';
$path = str_replace($q.'system/', '', $path);
}
return $path;
}
However it looks like the tcpdf does not support Alpha channels in png files, which doesn't affect me, but might be worth noting.
#14
#15
Thanks for the input Schoonzie, can you check if this patch works for you? Basically I just check the base path before the string replace:
if (base_path() != '/') {$path = str_replace(base_path(), '', $path);
}
#16
Hi you all. Last patch it's not working for me neither. But maybe is because I'm checking it on a localhost WAMP environment. Are you checking it on an online web server?
Curiously, if I comment the only line on previous pdfview_check_images function, instead of an inmediate error message it tries to rebuild the pdf file, it jumps to a new page, opens the acrobat plugin and then acrobat breacks.
#17
Schonzie, can you test if this using this
$path = preg_replace('^'.$GLOBALS['base_url'].'/', '', $path);$path = preg_replace('^'.base_path(), '', $path);
In place of
$path = str_replace($GLOBALS['base_url'].'/', '', $path);$path = str_replace(base_path(), '', $path);
Works for you?
Thanks
#18
Personaly, I use the 1.28.2.9 version and I also have a 'Missing or incorrect image file: /system/files/2903/something.jpg'
I guess the callback should get rid of the system or /system part of the filename but it does not. Besides it seems that the preg:
return preg_replace_callback('/(?<=src=")(.*?)(?=")/', '_pdfview_rewrite_image_url', $string);doesn't seem to match for the image as the callback is not called. Any help available please ?
#19
I can confirm that Schoonzie patch works for me.
see attached patch
#20
Hello. I struggled for a while getting images to display with pdfview because I have the files folder behind the public_html folder and private downloads set. I got things to work but ended up using the _pdfview_rewrite_image_url() function to set a url to the images, like "http://mysite.com/system/files/funk.jpg". Or I can send through the full path as /home/mysite/secretfiles/images/funk.jpg and everything works. Whatever I use for the K_PATH_IMAGE const doesn't seem to matter.
I read in the install file that the K_PATH_IMAGE was prepended to the drupal filepath. Is that old documentation? Am I going to mess things up going about this the way that I did, as mentioned above?
It seems that I'm missing something here. Or is it simply because I have the files folder behind public_html?
#21
Egon, your patch is not working for me, but Schoonzie's patch is working fine.
Now I have problems with URL Rewrite, TCPDF needs the absolute path...
#22
Herras, chantra, did you try #17 too?
geme4472, the documentation I wrote there makes the assumption that you're putting the files under the Drupal directory ... but if you change that path (K_PATH_IMAGES) to whatever you need to make your path absolute it should work
#23
Hello Egon!
I tried your patch and modification from #17. This is the error I got:
warning: preg_replace() [function.preg-replace]: No ending delimiter '^' found in /homepages/23/d162200924/htdocs/modules/pdfview/pdfview.module on line 253.
#24
I released Pdfview 4.7.x-1.1, it should fix problems with base_path
#25
Personaly, I use the pdfview.module 1.28.2.10 2007/01/27 version and
tcpdf.php Version : 1.53.0.TC027_PHP4 and
I also have a 'Missing or incorrect image file: /files/images/something.jpg'
I write at line 3840 of tcpdf.php :
$this->Image(K_PATH_IMAGES . $attr['src'], $this->GetX(),$this->GetY(), $this->pixelsToMillimeters(...[cut]instead of
$this->Image($attr['src'], $this->GetX(),$this->GetY(), $this->pixelsToMillimeters(...[cut]I don't know if the right way but the other above patch not good for me
#26
where's the difference between this issue and Doesn't show images in nodes?
I think they are dupes of each other