I'm currently working on a Django project and I need to convert HTML content to PDF, returning the PDF as a response. The library I choose should be able to fetch styles from an external CSS file and images from relative links. I've tried using Playwright but it requires inline CSS, and WeasyPrint is giving me a DLL issue that I can't seem to resolve.
6 Answers
Another option is wkhtmltopdf. I honestly gave up on trying to manage HTML to PDF conversions. Instead, I prefer creating a Word document that users can print or convert to PDF if needed; it feels way simpler to me.
I was going to suggest WeasyPrint since I find it useful, but I've only worked with it on Linux. If you’re working on Windows, you might want to check out html2pdf, though I'm not sure if it's still actively supported.
If you want to convert HTML with external CSS and images reliably, you should look at the Syncfusion .NET HTML-to-PDF Converter. It supports modern HTML5/CSS3 and works well. They have a free community license for individuals and small businesses.
I've had good success with TCPDF for generating PDFs. When creating reports, it allowed me to append content easily while handling pagination automatically. Let me know if you’d like a code sample for that.
Have you checked out Gotenberg? It's a service that might work well for your needs—check it out on GitHub!
Playwright is a solid choice. It’s a bit heavier since it runs a browser in headless mode, but it usually handles CSS and images decently. If your styles and images are static and don’t need authentication, just use full URLs in your templates.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically