DEV Community

Francesco Napoletano
Francesco Napoletano

Posted on

How to generate PDF from web pages

Originally published on my blog

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)