I am using PDFkit with python to convert an html page to pdf. In the html there is only one image tag in body with src pointing to a complete url like:
<html>
<body style="margin: 0px;">
<img style="-webkit-user-select: none; cursor: -webkit-zoom-in;" src="https://blah.blah.com" height="768">
</body>
</html>
However When I convert html to pdf like this:
pdfkit.from_file(file, 'labels.pdf', configuration=config)
I get a blank page with a box with border instead of image.
Why is pdfkit not converting image?
I read somewhere that we have to give full image path including domain name. But the image url I am providing is complete. Then what I am doing wrong?
I encoded the image as a string of Base64 data, following @Manish Gupta's suggestion. In Python:
import base64
def get_image_file_as_base64_data():
with open(FILEPATH, 'rb') as image_file:
return base64.b64encode(image_file.read())
In my Jinja2 template (I know the question isn't specific to Jinja2, but this is what I'm using):
<img src="data:;base64,{{ get_image_file_as_base64_data() }}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With