Images not getting displayed in PDF (barryvdh/laravel-snappy package)

1.7k Views Asked by At

I am using barryvdh/laravel-snappy package in Laravel framework to convert html file into PDF.

It is working fine, but images in the PDF are not getting displayed.

Image path used in the html is like:

https://easydmc-staging2.s3.ap-south-1.amazonaws.com/ImagesSightseeing/2021/03/1PeocnxOb3gqlZmMSjwXDWwLiEfyq0a8KX5M4OOw.jpeg

Here is the link of html:

https://staging.easydmc.com/test?html=true

And the link to generated PDF is:

https://staging.easydmc.com/test?html=false

Earlier the images were working fine in the PDF. A few days back I had executed the command - sudo apt upgrade. I do not whether this is causing the problem or not.

I tried re-installing the package barryvdh/laravel-snappy, but no success.

Any help would be appreciated.

PHP version: 8.0

Server: Nginx

Laravel: 8.51.0

2

There are 2 best solutions below

1
Mohsen Nazari On

I previously had this issue, it is because of wkhtmltopdf. You should use storage full path instead of web url.

For example instead of using:

https://easydmc-staging2.s3.ap-south-1.amazonaws.com/ImagesSightseeing/2021/03/1PeocnxOb3gqlZmMSjwXDWwLiEfyq0a8KX5M4OOw.jpeg

use something like this:

/var/www/html/myproject/public/ImagesSightseeing/2021/03/1PeocnxOb3gqlZmMSjwXDWwLiEfyq0a8KX5M4OOw.jpeg

to get the full storage path you can use code like below:

<img src="{{public_path('/ImagesSightseeing/2021/03/1PeocnxOb3gqlZmMSjwXDWwLiEfyq0a8KX5M4OOw.jpeg')}}" />
0
Mak_091 On

I got the solution:

First I checked whether there is an issue or not while generating the PDF using below command:

/usr/local/bin/wkhtmltopdf-amd64 http://www.google.com test.pdf

I got to know below issues:

QSslSocket: cannot resolve CRYPTO_num_locks                  ] 10%
QSslSocket: cannot resolve CRYPTO_set_id_callback
QSslSocket: cannot resolve CRYPTO_set_locking_callback
QSslSocket: cannot resolve sk_free
QSslSocket: cannot resolve sk_num
QSslSocket: cannot resolve sk_pop_free
QSslSocket: cannot resolve sk_value
QSslSocket: cannot resolve SSL_library_init
QSslSocket: cannot resolve SSL_load_error_strings
QSslSocket: cannot resolve SSLv3_client_method
QSslSocket: cannot resolve SSLv23_client_method
QSslSocket: cannot resolve SSLv3_server_method
QSslSocket: cannot resolve SSLv23_server_method
QSslSocket: cannot resolve X509_STORE_CTX_get_chain
QSslSocket: cannot resolve OPENSSL_add_all_algorithms_noconf
QSslSocket: cannot resolve OPENSSL_add_all_algorithms_conf
QSslSocket: cannot resolve SSLeay
QSslSocket: cannot call unresolved function CRYPTO_num_locks
QSslSocket: cannot call unresolved function CRYPTO_set_id_callback
QSslSocket: cannot call unresolved function CRYPTO_set_locking_callback
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function sk_num
QSslSocket: cannot call unresolved function SSLv23_client_method00%
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function SSL_library_init

The solution on above problem was to install libssl1.0-dev:

apt install libssl1.0-dev

So my PDF link https://staging.easydmc.com/test?html=false in original question started working now.