3

I am working in CakePHP 3 application. Here I am using TCPDF for PDF Generation. Everything works fine except image. Image is not displaying.

Here my pdf() action file:

public function pdf()
    {
    $this->loadModel('Users');
    $users=$this->Users->find('all')->select(['firstname','lastname','email','image_path']);
    $this->set(compact('users'));
    $this->viewBuilder()->layout('pdf');
    }

My pdf.ctp file :

$html = '<table>';

foreach($users as $users) {
  $html .= '<tr>
  <td>' . $users['firstname'] . '</td>
  <td>' . $users['lastname'] . '</td>
  <td>' . $users['email'] . '</td>
  <td><img src="/sample/webroot/img/'.$users['image_path'].'"/></td> 
        </tr>';    
}
$html .= '</table>';
$pdf->writeHTML($html, true, false, true, false, '');

Can any one help me to resolve this problem?

9
  • 1
    The src="" should use an absolute path to your image file such as /www/mywebsite.com/images/puppies.jpg Commented Jan 7, 2016 at 17:24
  • 1
    @MonkeyZeus. If I specified image file name directly means, it is displaying, like <td><img src="/sample/webroot/img/hmueegqsxy3n3rab3t69.jpg"/></td> . But When I specified like above means it is not showing Commented Jan 7, 2016 at 17:35
  • Are you positive it exists? Commented Jan 7, 2016 at 17:41
  • 1
    @ndm. Thanks. I find out the problem and now working fine. Commented Jan 12, 2016 at 13:01
  • 1
    How did you find out? Please write an answer then. Commented Sep 28, 2017 at 12:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.