If your web app creates report chances are you also want this report in PDF form. The Django docs describe a way to generate PDFs using ReportLab. Here is some code from there.
This suffers from two problems,
- You are laying out your PDF using Python, which means if you later want to change the design of the PDF you need to change the Python code.
- Most of the time you already have the report in Html, form, writing the same PDF via ReportLab is error prone.
HTML to PDF API - Python Learn how to convert web pages and HTML documents to PDF in Python using the Pdfcrowd API v2.The API is easy to use and the integration takes only a couple of lines of code. (5 replies) Hello Everyone I am using Reportlaba nd pisa to convert the html template to pdf and it is working but my question is that I want to convert the html template directly to pdf. Right now it is retrieving data from database but I dont want this thing.
Both these problems can be cleanly solved using Pisa, a Html2Pdf library. We proceed as,
- Generate a Html representation of Pdf using normal Django macienry.
- Convert to Pdf using Pisa.
- Return PDF.
This solves both our problems as,
- Designers can edit the template to change the layout of Pdf.
- The code to generate the Html and Pdf views can share code.
Here is some example code.
![Django Django](/uploads/1/2/6/2/126299043/145693001.jpg)
Thank you for reading the Agiliq blog. This article was written by shabda on Oct 7, 2008 in tips .
You can subscribe ⚛ to our blog.
We love building amazing apps for web and mobile for our clients. If you are looking for development help, contact us today ✉.
Would you like to download 10+ free Django and Python books? Get them here
Most people know how to write a page with HTML and CSS. Why not using these skills to dynamically generate PDF documents using it? The open source project 'pisa' http://www.htmltopdf.org enables you to to this quite simple in a pythonic way.
For the conversion these third party modules are used: HTML5lib, Reportlab and TG CSS Parser. All components are written in pure Python to ensure platform independency. More Informations on http://www.htmltopdf.org
This approach is very useful for web applications. Examples for integration with WSGI, Django, Turbogears, CherryPy and simple CGI are provided.
![Pdf Pdf](https://img-blog.csdnimg.cn/20190703221114107.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MTEzMzA2MQ==,size_16,color_FFFFFF,t_70)
Tags: web