Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate a report file (ODF, PDF) from a django view

I would like to generate a report file from a view&template in django. Preferred file formats would be OpenOffice/ODF or PDF.

What is the best way to do this?

I do want to reuse the page layout defined in the template, possibly by redefining some blocks in a derived template.

Ideally, the report should be inserted into an existing template file so I can provide the overall page layout, headers and footer in the generated output format.

like image 664
Ber Avatar asked Oct 22 '08 08:10

Ber


People also ask

How do I create a report in PDF in Django?

Generating a PDF file using DjangoDjango uses the ReportLab open-source PDF library to generate pdf files. This library needs to be installed using pip before using it. Django uses views to display the PDF files. Therefore, within your application, add the following code to your views.py file.

How do I read a PDF in PyPDF2?

Though PyPDF2 doesn't contain any specific method to read remote files, you can use Python's urllib. request module to first read the remote file in bytes and then pass the file in the bytes format to PdfFileReader() method. The rest of the process is similar to reading a local PDF file.


2 Answers

pisa/xhtml2pdf should get you covered for PDF. It even includes an example Django project.

like image 92
pantsgolem Avatar answered Oct 28 '22 04:10

pantsgolem


Try ReportLab for PDF output:

http://www.reportlab.org/

like image 26
Gabriel Ross Avatar answered Oct 28 '22 05:10

Gabriel Ross