when i open my invoice my invoice in pdf it doesnt show any image...while it shows the image in print...Please let me know how to fix it..

Comments

pathaksumit’s picture

Status: Active » Closed (fixed)
pietervogelaar’s picture

In the template is the variable $path_to_template available. Use this to get an full URL to your image.

Pieter

hanskuiters’s picture

Version: 6.x-1.1 » 7.x-1.0-beta2
Status: Closed (fixed) » Active

Re-open this issue for I can't get it to work in 7 version. I placed the image in the template directory. I can browse the image. It shows in browser and print. But it doesn't show in pdf. I cleared cache in database and browser.
Path to the image:

http://localhost:8888/crm/sites/all/modules/invoice/templates/logo-150.jpg

What can I do more to get it work?

hanskuiters’s picture

I found out I had to place more in the script section in the template. But still no image, just a red cross in the pdf. After searching on the web I found that people using just e dompdf without drupal, needed to use the path to the image, not the url. So I tried that but still no luck. And no errors in the log.

// Add a logo
$img_w = 2 * 72; // 2 inches, in points
$img_h = 1 * 72; // 1 inch, in points -- change these as required
$pdf->image("/Applications/MAMP/htdocs/crm/sites/all/modules/invoice/templates/logo-150.jpg", "jpg", ($w - $img_w) / 2.0, $y - $img_h, $img_w, $img_h );
hanskuiters’s picture

Suddenly I see the logo at the bottom of the pdf. Finally it does something. I can finetune now. But still the red cross at the top, just there where it is in the html. So I might need to unset something here?

hanskuiters’s picture

So, putting it in one post.

For the html you need the url to the image.
For the pdf you need the path to the image. And this image covers the red corss in the pdf.

So I changed my template.inc file.

// Set full url path to template
$url_to_template = _invoice_get_transfer_protocol() . '://' . $_SERVER['HTTP_HOST'] . base_path() . path_to_theme('module', 'invoice') . '/templates';
$path_to_template = $_SERVER['DOCUMENT_ROOT'] . base_path() . path_to_theme('module', 'invoice') . '/templates';
$image = '/logo-150.jpg';

And in the $footer variable

// Add a logo
$img_x = 400; $img_y = 15;  //position of image
$img_w = 120; $img_h = 144; //dimension of image
$pdf->image("'. $path_to_template . $image .'", "jpg", $img_x, $img_y, $img_w, $img_h );

I hope it helps someone. Took me a few hours to figure it out.

pietervogelaar’s picture

Assigned: Unassigned » pietervogelaar
Status: Active » Closed (fixed)

An example is added in the default invoice template in the stable release.

Pieter

nicholaspkelly’s picture

Seems to work as normal if gif images are used.