Sankar Subburaj
Sankar Subburaj

Reputation: 5042

Need to include image with PDF in Magento

I need to include the 'customer's logo' in the PDF file when we download it from invoice.

I tried with the following code.

$page->drawImage($customerLogo, 25, 800, 125, 825);

But it through the following fatal error...

Fatal error: Call to a member function getResource() on a non-object in D:\Application\xampp\htdocs\projects\guardian\lib\Zend\Pdf\Page.php on line 344

Any one knows, how to fix this problem.

Upvotes: 2

Views: 3158

Answers (2)

Chris Mousdale
Chris Mousdale

Reputation: 505

I have used this method before:

Place an image in image in your /media folder then where you want the image to appear inser this code:

$image = Mage::getConfig()->getOptions()->getMediaDir().DS.'you-logo-here.png';             
                        if (is_file($image)) {
                            $image = Zend_Pdf_Image::imageWithPath($image);
                            $page->drawImage($image, $x+5, $y-18, $x+45, $y-6);
                        }  

You will have to play with your php drawImage dimensions and coordinates. But this should do it.

Upvotes: 4

clockworkgeek
clockworkgeek

Reputation: 37700

For that error to occur $customerLogo must have been null. The answer is to make sure that $customerLogo is not null.

Upvotes: 0

Related Questions