How to generate PDF from web pages

For a little project of mine I had to generate PDF files from a fairly complex HTML web page.

The original page was created in PHP, so I’ve looked at libraries like dompdf and TCPDF I used many years ago. They’re still like 10 years ago… Not working well with CSS3 and tables.

After many tries the only library working fine was WeasyPrint. You can use in your Python projects or from the command line.

weasyprint https://napolux.com output.pdf

Perfect output and small PDF size. Give it a try!

If you want to share a comment or report an issue with this post, please send me an email to napolux@gmail.com

Share on: Twitter, Facebook, Reddit, Hacker News or go back home.