![]() ![]() To get pdfkit working, you’ll need to either add wkhtmltopdf to your PATH, or configure pdfkit to point to where the executable is stored (the latter option is used below). In the example below, we download Wikipedia’s main page as a PDF file. Response = 'attachment filename="gktcs. pip install pdfkit Once you’re set up, you can start using pdfkit. Response = HttpResponse(pdf,content_type='application/pdf') # Use False instead of output path to save pdf to a variable We can use the following code to return a PDF as response : We can retrieve directly a file from PDFKit and saving it in your system, just provide False as the destination parameter. The above example will create a PDF in the root of your Django project. To create a PDF file, we need to install the following libraries: pip install pdfkit pip install jinja2 Before we use the pdfkit library, we need to install wkhtmltopdf. Return HttpResponse("Everything working good, check out the root of your project to see the generated PDF.") Examplesįollowing examples shows easy way to generate PDFs with Django and PDFKit Save PDF on the server om_string('Hello!', 'document.pdf')Īnd we are basically generating PDFs easily and quick. Primer on Jinja2 Templates Jinja2 is a great tool to become familiar with, especially if you do web development in Python. pip install pdfkit import pdfkit pathwkhtmltopdf '/content/usr/bin/wkhtmltopdf' config nfiguration (wkhtmltopdfpathwkhtmltopdf) omurl ('test.html', 'out. # Generate PDF from a web URL (maybe only from your project) Note that you also need to install a tool called wkhtmltopdf for pdfkit to work. I tried to make pdfkit point to the path '/content/usr/bin/wkhtmltopdf' but didn't work.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |