user951449
user951449

Reputation: 3

How to Put image in generated pdf using Codeigniter

I am trying to generate the pdf in Codeigniter.I created it successfully but i am not able to put the image in that created pdf using codeigniter.Can you please help me to do this.

I look forward to hearing from you.

Upvotes: 0

Views: 4069

Answers (1)

Rooneyl
Rooneyl

Reputation: 7902

You need to append the document root to you image path.

E.g.

$image = getenv("DOCUMENT_ROOT").'/image_folder/my_image.png';
echo '<img src="'.$image.'" alt="My image" />

If the view is used for both html output and pdf then pass it a variable you can test, and add this if statement to your view;

if ($type == 'html')
{
    $root = $this->config->item('base_url');
}
else
{
    $root = getenv("DOCUMENT_ROOT").'/';
}

Then the PHP would be;

echo '<img src="'.$root.'image_folder/my_image.png" alt="My image" />';

Upvotes: 1

Related Questions