Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rretzko's avatar
Level 15

Weird <img> on pdf problem

Hi All - I'm hitting a weird problem getting an image to print on a pdf (barryvdh/laravel-dompdf v3.0.0). I use the following code on two applications. One app (TDR) works as expected, the second (SF) prints the alt value. The clip is copy/pasted from the working version to the non-working version, so I know there are no typos.

<img 
   src="{{ Storage::disk('s3')->url($dto['logoPdf']) }}"
   alt="{{ $dto['organizationName'] }} logo"   
   height="60" 
   width="60"
/>

The image sits on AWS S3 file. I've tried hard-coding the link and have hit the same problem. I've used the code on the screen display and it displays as expected. Any thoughts on how to troubleshoot this further are appreciated!

0 likes
2 replies
LaryAI's avatar
Level 58

When dealing with issues related to images not displaying in PDFs generated by libraries like barryvdh/laravel-dompdf, there are a few common areas to investigate:

  1. Check Image Accessibility: Ensure that the image URL is publicly accessible. Since the image is stored on AWS S3, make sure the bucket policy or the specific file permissions allow public access. You can test this by trying to access the image URL directly in a browser.

  2. Use Absolute URLs: DOMPDF requires absolute URLs to fetch images. Ensure that the URL generated by Storage::disk('s3')->url($dto['logoPdf']) is indeed an absolute URL.

  3. Check for SSL Issues: If your S3 bucket is using HTTPS, ensure that your server's PHP configuration supports SSL. Sometimes, DOMPDF might have issues fetching images over HTTPS if the server's SSL configuration is not set up correctly.

  4. Enable Remote Assets: Make sure that DOMPDF is configured to allow remote assets. You can enable this in your config/dompdf.php file:

    'enable_remote' => true,
    
  5. Check for Errors: Enable error reporting in DOMPDF to see if there are any specific errors related to image fetching. You can do this by setting the log_output_file in the config/dompdf.php:

    'log_output_file' => storage_path('logs/dompdf.log'),
    

    Then, check the log file for any errors that might give you more insight.

  6. Test with a Local Image: As a troubleshooting step, try using a local image file to see if it displays correctly. This can help determine if the issue is with the remote image fetching.

  7. Check for CORS Issues: Although less common with PDF generation, ensure that there are no CORS issues preventing the image from being fetched.

By following these steps, you should be able to identify the root cause of the issue and resolve it. If the problem persists, consider checking the library's GitHub issues page or forums for similar problems and solutions.

lotusCupcake's avatar

Hello Rretzko, I am facing the same issue like you before, I try to retrieve online image in pdf view. After many surfing in internet, fortunately I found this solution,

$pdf = Pdf::loadView('pdf.view, compact('user', 'data'));
$pdf->getDomPDF()->getOptions()->setIsRemoteEnabled(true); // add this line
return $pdf->setPaper('A6', 'landscape')->stream('test.pdf');

Have a nice day!

*sorry for bad english

Please or to participate in this conversation.