0
votes

I am using DOMPDF to generate pdf.

Here is my pdf.blade.php:

<img src="{{ public_path() . '/images/logo.png' }}" id="logo" />
<table class="order_confirmation"> 
    <tbody>
        <tr>
            <th>Company name</th>
            <td>Name</td>
        </tr>
        <tr>
            <th>Email</th>
            <td>[email protected]</td>
        </tr>
    </tbody>
</table>

Here is my controller method:

public function pdf() {
    $data = array();
    $pdf = PDF::loadView('pdf', $data);
    return $pdf->stream();
}

Here is error:

ErrorException in class.pdf.php line 4036: imagepng(.png): failed to open stream: Permission denied

And a stacktrace:

in class.pdf.php line 4036 at HandleExceptions->handleError('2', 'imagepng(.png): failed to open stream: Permission denied', '/Applications/XAMPP/xamppfiles/htdocs/blablacompany/vendor/dompdf/dompdf/lib/class.pdf.php', '4036', array('file' => '/Applications/XAMPP/xamppfiles/htdocs/blablacompany/public/images/logo.png', 'x' => '34.015748031496', 'y' => '606.8742519685', 'w' => '334.5', 'h' => '201', 'byte' => '6', 'img' => 'Resource id #278', 'eight_bit' => false, 'wpx' => '446', 'hpx' => '268', 'tempfile_alpha' => '.png', 'tempfile_plain' => '.png', 'imgalpha' => resource, 'c' => '256', 'allocated_colors' => array('000' => '0', '9598261', '12756008', '9993266', '15848487', '7493443', '12690472', '16309032', '14269479', '5586004', '11637804', '16243240', '8809018', '2169210', '12624680', '15256615', '6638155', '2366072', '5454677', '10256177', '13151271'...

Could you please help me?

P.S.

  1. I have tried also url('/images/logo.png') instead of public_path() . '/images/logo.png'
  2. I have chmod 777 on storage, vendors and also on public/images, but still not working...

ErrorException in image_cache.cls.php line 105: file_put_contents(): Filename cannot be empty

UPDATE:

  • if I set chmod 754 and return view('pdf') -> image is not shown (as well as on other pages which are using images/
  • if I set chmod 754 and $pdf = PDF::loadView('pdf', $data); return $pdf->stream(); -> PDF is generated but image is stroked square
  • but if I set chmod 755 and return view('pdf') -> images is shown, but..
  • when I try $pdf = PDF::loadView('pdf', $data); return $pdf->stream(); I receive an error message:

ErrorException in image_cache.cls.php line 105: file_put_contents(): Filename cannot be empty

1
Honestly, I don't understand what I have done, why it's working like that, maybe someone could explain: MacBook-Air:public myuser$ sudo chmod -R 777 images/ - not working MacBook-Air:public myuser$ sudo chmod -R 755 images/ - not working MacBook-Air:public myuser$ sudo chmod -R 754 images/ - WORKING . Now at least pdf is generated but images looks like stroked square.. but this is probably another issueAleksandrs

1 Answers

1
votes

I figured out how to deal with it:

  1. for pdf generation you should use public_path() instead of url('') (e.g. <img src="{{ public_path() . '/images/somepicture.jpg' }}" id="logo" />),
  2. public_path() won't work if want to load view return view('yourview');

  3. Use only .jpg, .png won't work

  4. chmod 755 your image folder