how to create pdf report in web2py???

1,987 views
Skip to first unread message

prashant joshi

unread,
May 10, 2016, 12:59:47 PM5/10/16
to web2py-users
how to create pdf report in web2py?  i saw video on vimeo but this plugin not found..

Dave S

unread,
May 10, 2016, 2:26:59 PM5/10/16
to web2py-users
On Tuesday, May 10, 2016 at 9:59:47 AM UTC-7, prashant joshi wrote:
how to create pdf report in web2py?  i saw video on vimeo but this plugin not found..


There are multiple ways to do it, but one way (which is briefly mentioned in the web2py book, and the pieces are in contrib)
is shown at 

 The fpdf link shown in the book appears to be out of date; try
(Mariano has additional credits in contrib)

/dps

José Luis Redrejo

unread,
May 10, 2016, 2:40:42 PM5/10/16
to web...@googlegroups.com
Latest fpdf code is in the contrib section of gluon libraries, and works correctly. If your report is not too complicated I'd recommend you this way. The demo from the above link is easy to follow.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jim S

unread,
May 10, 2016, 3:52:07 PM5/10/16
to web2py-users
I use ReportLab...

-Jim

Carlos Cesar Caballero Díaz

unread,
May 10, 2016, 4:26:45 PM5/10/16
to web...@googlegroups.com
Take a look to jsPDF (https://parall.ax/products/jspdf) if you are more familiar with javascript.



El 10/05/16 a las 15:52, Jim S escribió:

prashant joshi

unread,
May 16, 2016, 6:19:08 AM5/16/16
to web...@googlegroups.com
i also try this but i could not understad....please anybody send a simple example that i will understd

Dragan Matic

unread,
May 16, 2016, 4:49:55 PM5/16/16
to web2py-users
Here's a simple example, creating a PDF invoice in web2py app:

This is the controller code:
def show_pdf_invoice(invoice_number, invoice):
   
from fpdf import FPDF

    pdf
= FPDF()
    pdf
.add_page()

    pdf
.set_font('Arial', 'B', 10)
    pdf
.cell(25, 5, 'My company name', )
    pdf
.set_font('Arial', '', 10)
    pdf
.cell(60, 5, 'My company address', ln=1)
    pdf
.cell(40, 5, 'My company additional data', ln=1)
    pdf
.line(10, 20, 180, 20)

    pdf
.set_xy(140, 25)    
    pdf
.cell(25, 5, 'Date issued: {0}'.format(invoice[0].date))
    pdf
.set_xy(140, 30)    
    pdf
.cell(25, 5, 'Invoice Number: {0}'.format(str(invoice_number)))

    pdf
.line(10, 40, 180, 40)
    pdf
.set_xy(10, 41)
    pdf
.cell(30, 5, 'Description')
    pdf
.cell(30, 5, 'Starts')
    pdf
.cell(30, 5, 'End')
    pdf
.cell(30, 5, 'Amount')
    pdf
.line(10, 46, 180, 46)

    pdf
.set_xy(10, 47)
    pdf
.cell(30, 5, invoice[0].invoice_item_name)
    pdf
.cell(30, 5, '')
    pdf
.cell(30, 5, '')
    pdf
.cell(30, 5, '{0} {1}'.format(invoice[0].total, invoice[0].currency)
    pdf
.line(10, 51, 180, 51)

    pdf
.set_xy(150, 52)
    pdf
.cell(30, 5, 'Total: {0} {1}'.format(invoice[0].total, invoice[0].currency)

    pdf
.set_xy(10, 60)

    pdf
.cell(30, 5, 'Bill To:', 0, 1)
    pdf
.cell(30, 5, invoice[0].invoice_address_name, 0, 1)
    pdf
.cell(30, 5, invoice[0].invoice_address_street, 0, 1)
    pdf
.cell(30, 5, invoice[0].invoice_address_city)
    pdf
.cell(30, 5, invoice[0].invoice_address_zip, 0, 1)
    pdf
.cell(30, 5, invoice[0].invoice_address_country)

    pdf
.output('invoice.pdf', 'F')
           
    response
.headers['Content-Type'] = 'application/pdf'    
   
return XML(pdf.output('', 'S'))    



And that's it, your view named "show_pdf_invoice.html" should be empty. 

Dave S

unread,
May 18, 2016, 2:59:40 PM5/18/16
to web2py-users
If you prefer to maintain an MVC style,  my sample at
approaches that, and also shows using a ROWS object if your project requires results from one of your tables.

/dps

prashant joshi

unread,
May 19, 2016, 1:21:24 AM5/19/16
to web...@googlegroups.com
according to this video i have already done shown in this video after adding appreport plugins i,m getting error:

<type 'exceptions.ImportError'> Cannot import module 'applications.report.modules.modules'

please suggest me what to do further???/



prashant joshi

unread,
May 19, 2016, 5:29:38 AM5/19/16
to web...@googlegroups.com
how to download  appreport_plugin  ......??? this show in video

prashant joshi

unread,
May 19, 2016, 5:49:39 AM5/19/16
to web...@googlegroups.com
 also download from it will be not work 

Cannot import module 'applications.bbb.modules.modules'

this error show again

Dave S

unread,
May 19, 2016, 8:22:14 PM5/19/16
to web2py-users
On Wednesday, May 18, 2016 at 10:21:24 PM UTC-7, prashant joshi wrote:
according to this video i have already done shown in this video after adding appreport plugins i,m getting error:

<type 'exceptions.ImportError'> Cannot import module 'applications.report.modules.modules'

please suggest me what to do further???/



Can you show us your code?
 
/dps

prashant joshi

unread,
May 20, 2016, 1:29:31 AM5/20/16
to web...@googlegroups.com
db-
db = DAL("postgres://postgres:postgres@localhost:5432/report1")

from gluon.tools import Auth
auth = Auth(db)
auth.define_tables(username=True,signature=False)
db.define_table('register',
    Field('first_name', requires=IS_NOT_EMPTY()),
    Field('last_name', requires=IS_NOT_EMPTY()),
    Field('course', requires=IS_NOT_EMPTY()),
    Field('roll','integer', requires=IS_NOT_EMPTY()),
    Field('contact', requires=IS_NOT_EMPTY()))



cantroller:-
def  report():
    form=pluging_appreport.REPORTFORM(register)
    if form.accpept(request.vars,session):
        return pluging_appreport.REPORT(table=register,title='user',filter=dict(form.vars))
    return dict(form=form)



view:-default/report
{{extend 'layout.html'}}
{{=form}}




 is it correct??? if not then tell me the correct code?

Alex

unread,
Aug 26, 2017, 9:19:30 AM8/26/17
to web2py-users
We created a report tool since creating pdf reports in a web application is a common problem and none of the existing solutions were optimal for us. We needed something that is easy to integrate, easy to use (to design the reports) and easy to maintain (e.g. to create new versions of an existing report template).


The designer to create report templates is a javascript plugin which can easily be integrated in a web application. Server-side we developed a python package - which you can either download or install via pip - to create the pdf (or xlsx) file with a given report template and data. Because it's python it is easy to use in an existing web2py app.

We appreciate any kind of feedback!

Alex

António Ramos

unread,
Aug 28, 2017, 1:47:45 PM8/28/17
to web...@googlegroups.com
We have a winner.
Great tool...


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

Javier Pepe

unread,
Aug 29, 2017, 9:15:52 AM8/29/17
to web...@googlegroups.com
Alex

The tool is very good, you have a user list for question, i am to try the designer and not found howto save this.

Thanks

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

Alex

unread,
Aug 29, 2017, 10:49:37 AM8/29/17
to web2py-users
Thanks!

at the moment we don't have a user list, but that's something we have to think about. You can also contact us per mail.

One way to save the report is using the localStorageReportKey setting (see https://www.reportbro.com/docs/options ), e.g.
$("#reportbro").reportBro({
    localStorageReportKey: 'myReportKey'
});

this way the report is saved on the client in local storage with given key when you click the save button. When the plugin is initialized the report is automatically loaded from local storage. This is fine for testing but in a real-world application you usually want to save the report in your application (database).

For this you can use the saveCallback option, e.g.
function saveReport() {
    var report = $('#reportbro').reportBro('getReport');

    $.ajax('<your save controller url>', {
        data: JSON.stringify(report),
        type: "PUT", contentType: "application/json",
        success: function(data) {
            ...
        },
        error: function(jqXHR, textStatus, errorThrown) {
            ...
        }
    });
}
    
$(document).ready(function() {
    $('#reportbro').reportBro({
        saveCallback: saveReport
    });
});

how you are saving the report server-side is up to you.

Alex
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Massimo Di Pierro

unread,
Aug 31, 2017, 6:08:53 PM8/31/17
to web2py-users
Nice!

Alex

unread,
Sep 8, 2017, 1:39:31 PM9/8/17
to web2py-users
We created a user group at https://groups.google.com/forum/#!forum/reportbro
Don't hesitate to post in case you have any questions.

I added the custom save example from above to our demos:
https://github.com/jobsta/reportbro-designer/blob/master/demos/custom_save.html

Ramos

unread,
Nov 21, 2017, 6:33:47 PM11/21/17
to web2py-users
Does someone have a web2py working example with reportbro???

Thank you

Alex

unread,
Nov 22, 2017, 5:38:11 AM11/22/17
to web2py-users
you can find basic information here:
https://www.reportbro.com/docs/installation

client side you only have to initialize the plugin. For server integration with web2py there is an example implementation as well:
https://www.reportbro.com/static/download/reportbro_web2py.py

António Ramos

unread,
Nov 22, 2017, 6:07:56 AM11/22/17
to web...@googlegroups.com
Not that easy :)

i´m reading your links and also this link

where i´m stuck in the save part

what url do i put in the save url ?
Imagem inline 1

i moved the run function from the reportbro_web2py.py to a controller and i use it in the above "your save controller url" but i get a bad request in the browser when i do in the console
$('#reportbro').reportBro('save')

Thank you


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

António Ramos

unread,
Nov 22, 2017, 6:18:25 AM11/22/17
to web...@googlegroups.com
Imagem inline 1

Alex

unread,
Nov 22, 2017, 7:35:58 AM11/22/17
to web2py-users
On Wednesday, November 22, 2017 at 12:07:56 PM UTC+1, Ramos wrote:
Not that easy :)

i´m reading your links and also this link

where i´m stuck in the save part

what url do i put in the save url ?

that's up to you. e.g.
'{{=URL('report', 'save')}}'
so you would need a controller file report.py with a function save in your application. There you have to save the report (available as data parameter) yourself wherever you want to. E.g. you could save it in your db or as a file.

In your case you don't have the controller you specified in the url, therefor the ajax call fails.

António Ramos

unread,
Nov 22, 2017, 7:46:06 AM11/22/17
to web...@googlegroups.com
Some questions ...

1 - i see that you have already a report_request table with the reports.
Are you talking about this table to save reports? Looks to me that this table is to save the "templates" of the pdf reports


2 - How do i merge data from my db with your templates and generate a live pdf with live data? so users can save it in their desktop ?

regards
António

Alex

unread,
Nov 22, 2017, 8:31:03 AM11/22/17
to web2py-users
On Wednesday, November 22, 2017 at 1:46:06 PM UTC+1, Ramos wrote:
Some questions ...

1 - i see that you have already a report_request table with the reports.
Are you talking about this table to save reports? Looks to me that this table is to save the "templates" of the pdf reports

this is a different table to temporarily store report definition and data. It is used as a workaround for the plugin. The data for pdf preview in MS Edge browser cannot be set directly and needs a url instead. Further this is also needed for xls preview, because there is no simple preview plugin for xls. Therefor the url for xls preview is opened in a new tab and handled by the browser.
 
2 - How do i merge data from my db with your templates and generate a live pdf with live data? so users can save it in their desktop ?

in your web2py controller (where you generate the final pdf file) create a Report instance:
report = Report(report_definition, data)

where report_definition is the report template (the one you uploaded to your save controller), and data is a dict containing the actual data to fill in. the keys must match with your parameters of the report. E.g. if you have a parameter "first_name" then data must contain a key "first_name". You should check afterwards if there were any errors during report initialization (report.errors)

the report itself (pdf file) is created with
report_file = report.generate_pdf()


regards
António

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

António Ramos

unread,
Nov 22, 2017, 9:56:33 AM11/22/17
to web...@googlegroups.com
Great. Will investigate further...

Also another question

the reportbro logo at the bottom of the pdf is there to stay?

I´m doing a private app for my business. Do i need to pay any licence?
How do i remove that logo in the bottom of the page?

Regards
António

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

António Ramos

unread,
Nov 22, 2017, 10:45:32 AM11/22/17
to web...@googlegroups.com
I got it .
I have to read the record from the report_request table and do a json.load before the 
Report(definition, mydata)
also in the designer i have to create paramenters...

Thank you

António Ramos

unread,
Nov 22, 2017, 11:03:41 AM11/22/17
to web...@googlegroups.com
About fonts

there is only available

Courier new
Helvetica
Times new roman

I need aria, how do i add it ?

adding it to static folder and changing the addicional_fonts does not work
Imagem inline 1

Regards

Alex

unread,
Nov 22, 2017, 3:37:20 PM11/22/17
to web2py-users
you do not have to buy a license for a private app:
https://www.reportbro.com/license/index

the logo is only printed when using the public available reportbro instance. When you use your own server there will not be a logo on the generated pdf file. Unless you call generate_pdf with add_watermark=True parameter:
https://www.reportbro.com/docs/methods

you should not read the report template from the report_request table, because it is only used as a temporary table for the plugin (as mentioned above). You should store your report template yourself (in your save controller) and then use this template (from db or file system etc.) to generate a report.

about the fonts: what does not work? first you have to add it when initializing the plugin so the font is available in the designer. This is demonstrated in the certificate demo:
https://www.reportbro.com/demos/index

On the server you have to specify the additional_fonts parameter,  the value of the font must be the same as the value in the plugin intialization (so the font matches). And of course the specified ttf file must exist (in your case static/fonts/arial.ttf)

António Ramos

unread,
Nov 23, 2017, 6:12:15 AM11/23/17
to web...@googlegroups.com
Thank you for your help.


To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

António Ramos

unread,
Nov 23, 2017, 6:50:02 AM11/23/17
to web...@googlegroups.com
I´m setting the page margins but the pdf and printed paper dont assume that value

Imagem inline 1

Imagem inline 2

António Ramos

unread,
Nov 23, 2017, 7:49:05 AM11/23/17
to web...@googlegroups.com
problem solved...
thank u

António Ramos

unread,
Nov 23, 2017, 7:53:26 AM11/23/17
to web...@googlegroups.com
@alex
you said
if you have a parameter "first_name" then data must contain a key "first_name".

What is the point of the ${variable} in your demos?
do i need the ${} ?


To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

António Ramos

unread,
Nov 28, 2017, 7:44:02 AM11/28/17
to web...@googlegroups.com
Another question.
A simple pdf created with reportbro is 560Kb in size.
Why is it soo big??

Regards
testreport.pdf

Alex

unread,
Nov 28, 2017, 8:29:33 AM11/28/17
to web2py-users
your attached report is only 1,8 kB

reports can get large in case you include large images. currently the image data itself is not resized, so if you have a very large image the report could get very large as well. Further if you use additional fonts the fonts are embedded in the pdf.

about the variables question: variables are basically placeholders so you can design only one template with dynamic data. You probably don't want to create a new template for each invoice etc. In your testreport example you would have variables for client, transportador, product, etc. so you can use one template and feed it with the appropriate data when generating the pdf.

António Ramos

unread,
Nov 28, 2017, 8:33:17 AM11/28/17
to web...@googlegroups.com
Great
I´m loving your tool...
Regards


--

Alex

unread,
Sep 25, 2018, 2:46:36 PM9/25/18
to web2py-users
We just released ReportBro v1.0!

besides new features (e.g. sections) and bugfixes we also updated the documentation. There is an own section how to integrate ReportBro into your web application:

we include a demo application which is available for both Django and web2py so it's easier for you to understand how everything fits together.

regards,
Alex
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages