0

I have a large html file. I am facing issue when I am converting HTML to PDF file CSS is not supporting. I used CSS all the way like inline, internal and external.

When I use CSS like this it working fine:

<img class="object" src="https://cdn.shopify.com/s/files/1/0604/2884/5310/files/animated-sun.png?v=1652249417" height="50" width="50" alt="" id="sun">

but when I use this

<img class="object" src="https://cdn.shopify.com/s/files/1/0604/2884/5310/files/animated-sun.png?v=1652249417" style="height:50px; width:50px;" alt="" id="sun" top="" left="">```

it is not working, even I used all way of CSS internal, external and inline.

I want to use CSS like this

<img class="object" src="https://cdn.shopify.com/s/files/1/0604/2884/5310/files/animated-sun.png?v=1652249417" style="height:50px; width:50px;" alt="" id="sun" top="" left="">

I am using this to convert:

wkhtmltopdf --enable-local-file-access --disable-javascript --page-size A0 input.html output.pdf

I use wkhtmltox_0.12.6.1-2.jammy_amd64.deb

Robert
  • 7,394
  • 40
  • 45
  • 64

1 Answers1

0

This python code seems to work with the way you wanted the CSS to look like:

import pdfkit
pdfkit.from_file('your_html_file.html', 'out.pdf')

if you want to add flags, you can do:

import pdfkit
kitoptions = {
    "enable-local-file-access": None,
    # more flags...
}
pdfkit.from_file('your_html_file.html', 'out.pdf', options=kitoptions)

Make sure you have wkhtmltopdf.exe in your script's folder. For all flag options, click here

Idan Rotbart
  • 93
  • 1
  • 5