Blog Details
Blog Title: | Create PDF using HTML template in Django | ||||||
---|---|---|---|---|---|---|---|
Blogger: | hadoleamit@gmail.com | ||||||
Image: | View | ||||||
Content: | In this blog, we will learn how to create PDFs using wkhtmltopdf in Django. RequirementsYou need wkhtmltopdf available in your system and accesible in the command prompt. Windows: you can download an installer for each architecture (x86 and x64) in the installation area. Although you can change the path of the wkhtmltopdf executable later in the code, is recommendable to have wkhtmltopdf accesible as an environment variable on your system. Debian/Ubuntu: You can install the distribution from wkhtmltopdf directly in the console using the following command :
ImplementationPDFKit is a python wrapper to convert html to pdf using the webkit rendering engine (wkhtmltopdf) and qt. Include the PDFKit library into your django project using the following command :
The use of PDFKit is really simple and cover almost all the use cases :
And we are basically generating PDFs easily and quick. ExamplesFollowing examples shows easy way to generate PDFs with Django and PDFKit Save PDF on the server
The above example will create a PDF in the root of your Django project. Return PDF as responseWe can retrieve directly a file from PDFKit and saving it in your system, just provide False as the destination parameter. We can use the following code to return a PDF as response :
PDF SettingsYou can specify all wkhtmltopdf options. You can drop ‘–’ in option name. If option without value, use None, False or '' for dict value:
wkhtmltopdf Output |