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

Egon Bianchet - July 31, 2006 - 17:04

It's the one shipped by Drupal (drupal/misc/arrow-asc.png).

What kind of node is involved?

#2

mfitch - August 1, 2006 - 18:18

it's a php page generated by the tablemanager module

<?php
print 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

Egon Bianchet - August 8, 2006 - 07:01

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

mfitch - August 11, 2006 - 22:16

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

Egon Bianchet - August 14, 2006 - 14:32
Status:active» fixed

I committed a fix in the 4.7 version. Now it finds the image, but the output isn't good looking

#6

mfitch - August 16, 2006 - 15:10
Status:fixed» active

now I'm seeing a different error: FPDF error: Image file has no extension and no type was specified:

any ideas?

#7

Egon Bianchet - September 17, 2006 - 20:19

I improved the image url/path filter ... check the latest 4.7 version and see if it works.

#8

Egon Bianchet - October 31, 2006 - 17:32
Title:failing: Can't open image file: /misc/arrow-asc.png» Pdf output broken for nodes with images

Changed to a meaningful title

#9

Egon Bianchet - November 3, 2006 - 09:25
Status:active» patch (code needs review)

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/");

AttachmentSize
pdfview-images.patch.txt1.26 KB

#10

Egon Bianchet - November 13, 2006 - 23:35

I went ahead and committed it

#11

Egon Bianchet - November 13, 2006 - 23:35
Status:patch (code needs review)» fixed

#12

Schoonzie - November 14, 2006 - 03:09

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

Schoonzie - November 14, 2006 - 03:19

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

Egon Bianchet - November 17, 2006 - 07:40
Status:fixed» patch (code needs work)

#15

Egon Bianchet - November 19, 2006 - 12:36
Status:patch (code needs work)» patch (code needs review)

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);
  }

AttachmentSize
pdfview-images-1.patch.txt821 bytes

#16

JordiTR - November 22, 2006 - 14:34

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

Egon Bianchet - December 7, 2006 - 14:16

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

pvasener - December 20, 2006 - 16:24

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

chantra - January 9, 2007 - 12:32

I can confirm that Schoonzie patch works for me.
see attached patch

AttachmentSize
pdfview_image.patch651 bytes

#20

geme4472 - January 11, 2007 - 23:07

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

Herras - January 14, 2007 - 21:35

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

Egon Bianchet - January 15, 2007 - 09: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

Herras - January 15, 2007 - 20:18

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

Egon Bianchet - January 27, 2007 - 09:52

I released Pdfview 4.7.x-1.1, it should fix problems with base_path

#25

marcod - February 2, 2007 - 18:08
Version:4.7.x-1.x-dev» 4.7.x-1.1

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

Tobias Maier - February 3, 2007 - 08:30
Status:patch (code needs review)» duplicate

where's the difference between this issue and Doesn't show images in nodes?
I think they are dupes of each other

 
 

Drupal is a registered trademark of Dries Buytaert.