barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.59k stars 289 forks source link

Insert image in pdf #414

Closed radcloudcorp closed 3 years ago

radcloudcorp commented 3 years ago

Hello good afternoon. I've tried several ways to insert an image in the pdf and I can't. I've tried it with some versions of snnapy and wkhtmltopdf and I couldn't. I saw a video on youtube at https://www.youtube.com/watch?v=P43fuBbmD1c&t=13s where the person can do it without complications. I try to do it in the same way even with the same photo link that he uses http://placekitten.com/130/130 but the error is and the pdf is not generated. I would be very grateful for any help.

Test with snnapy 0.4.6 and 0.4.8, and wkhtmltopdf versions 0.12.5 and 0.12.6

ChaplyginWezom commented 3 years ago

@radcloudcorp Hi! Have you tried to set 'enable-local-file-access' option to true and print image using real path to it instead of url?

PDF::setOption('enable-local-file-access', true)->loadView('pdf.example', $data);

<img src="/c/real-path-to-file/image.png">

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy. If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.

hammadshah01 commented 5 months ago

When you print PDF with image it throw some error to use images in PDF file then you can modify your controller and blade file

//FOR CONTROLLER PDF::setOption('enable-local-file-access', true)->loadView('pdf.example', $data);

//FOR BLADE (_PLZ USE PUBLICPATH() INSTEAD OF ASSET() )

hammadshah01 commented 5 months ago

@radcloudcorp Hi! Have you tried to set 'enable-local-file-access' option to true and print image using real path to it instead of url?

PDF::setOption('enable-local-file-access', true)->loadView('pdf.example', $data);

<img src="/c/real-path-to-file/image.png">

yes thats legit use public_path('you file loacal address')