OT PollyReports generate PDF using bands from DB

100 views
Skip to first unread message

DenesL

unread,
Oct 1, 2020, 2:58:39 PM10/1/20
to web2py-users

While searching for a Python PDF package I found PollyReports and was pleasantly surprised by it, and it is also nicely documented.

PollyReports is a small, light module providing a simple way to generate reports from databases using Python.

Other features (subreports): https://opensource.gonnerman.org/?cat=4

I hope you find it as useful as I did.

Regards,
Denes



AGRogers

unread,
Oct 5, 2020, 1:18:26 AM10/5/20
to web...@googlegroups.com
Thanks Denes. I have often looked for reporting solutions over the years. I will keep it in mind.

___________________________
www.TenOutOfTen.org



--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/53fdf8b1-d571-4e60-a9cc-1d000524043fn%40googlegroups.com.

villas

unread,
Oct 6, 2020, 11:47:48 AM10/6/20
to web2py-users
It is strange that Geraldo Reports and PollyReports do not seem to have been maintained for years. 
Maybe everyone is using something else these days? 

António Ramos

unread,
Oct 6, 2020, 2:13:14 PM10/6/20
to web...@googlegroups.com
my favourite

i has a web2py tutorial of installation.

--
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.

Clemens

unread,
Oct 6, 2020, 3:16:18 PM10/6/20
to web2py-users
Hi,

my fav is just to write a TeX file by Python and then trigger LaTeX to produce the PDF document. I'm using this solution since 2 years after I was really frustrated by the Python PDF packages available. LaTeX gives you all freedom to produces a PDF document, it's perfectly documented (finding a solution for every problem), it's absolutely stable, it can be expanded by packages, you have things like a table of contents ... Long story short: I like it!

Regards
Clemens

DenesL

unread,
Oct 31, 2020, 10:29:53 PM10/31/20
to web2py-users
@roger: you are welcome.
@villas: probably reportlab.
@ramos: reportbro is open-source license for non-commercial open-source or personal projects only.
@clemens: interesting but you probably have to handle everything e.g. page breaks, page headers, etc. , right?.

My need was to generate PDF documents (e.g. invoices) with report headers/footers, page headers/footers, detail lines, and even sub-reports from database queries without having to handle all the intricacies (e.g. page breaks, total, page numbers, etc.) and PollyReports fit the bill in a small and easy to use package.

What is missing is a WYSIWYG page designer to simplify the layout creation.
As an alternative I have been looking for a way to convert a template created by some open source program such as OpenOffice, FreeOffice,  or LibreOffice to the bands/elements used in PollyReports but without much luck so far.

Regards,
Denes

Clemens

unread,
Nov 1, 2020, 12:52:56 PM11/1/20
to web2py-users
Hi, you're right, I'm generate everything, because I need this in my case. BUT: You can use LyX as WYSIWYG editor generating the TeX file (pure text). Then just find and replace the things you want to adapt (e.g. date). This should be easy. If you want to evaluate this way and you need some more assistance, please let me know.

Best regards
Clemens

DenesL

unread,
Nov 1, 2020, 11:51:40 PM11/1/20
to web2py-users
Hi Clemens

does TeX, or any of other formats supported by LyX, store the position on the page (x,y), formatting (e.g. font type and size), alignment or other valuable information about text elements that could be used to generate PollyReports Elements & Bands ?

Regards,
Denes

Clemens

unread,
Nov 2, 2020, 9:01:16 AM11/2/20
to web2py-users
Hi, you can realize absolute positioning by the TeX package texpos. But I don't know PollyReports very well, I only heard of it. Thus, do you have an example PDF on what you want to generate?

Regards
Clemens

DenesL

unread,
Nov 2, 2020, 4:36:07 PM11/2/20
to web2py-users
Sounds promising.
Below is an example of a PollyReport.
Each band (B) contains a list of elements (E).
For each E you can define pos=(x,y), font=(name,size), text, key, align, width (among other parameters).
Note that an element's x,y is relative to the containing band's x,y (top left corner).
So maybe use a texpos box around a table with one row and try to get relative positions that way.
Note: 72dpi, so x=600 is 8.33 inches from the left edge of the band

H = ("Helvetica", 10)
HB = ("Helvetica-Bold", 10)
E = PR.Element
B = PR.Band
Rule = PR.Rule # horizontal line
R = "right"

rep = PR.Report(rr)
rep.titleband = B([ E((600, 0), ("Times-Bold", 20), "Picklist"),
  E((36,30), H, f"Ship to\n{soi[4]} {soi[5]}\n{adr}"), E((380,30), H, now), # soi = sales order query results
  E((480,30), H, f"Order\n{so}"), E((560,30), H, f"Doc.Date\n{dd}"), E((630,30), H, f"Allow partial\n{soi[2]}"),
  E((480,60), H, f"MoT: {soi[7]}\nRemarks: {soi[3]}"),
])
rep.groupheaders = [ B([ Rule((36,0),650),], getvalue = lambda x: x[0] ), ]
rep.pageheader = B([
  Rule((36,0),650),
  E((90,0), H, "Item Number"), E((166,0), H, "Description"), E((410,0), HB, "Pick Qty", align=R),
  E((450,0), H, "UoM"), E((538,0), H, "Bin Location", align=R), E((626,0), H, "OnHand", align=R),
  E((680,0), H, "Picked", align=R),
  Rule((36,12),650),
])
rep.pagefooter = B([ E((72*7, 0), H, sysvar = "pagenumber", format = lambda x: f"[{now}]  Order {so} page {x}"), ])
rep.detailband = B([ E((52,0), H, getvalue=lambda r: r[1]+1, align=R),
  E((90,0), H, key=2), E((166,0), H, key=8), E((410,0), HB, key=6, align=R),
  E((450,0), H, key=9), E((573,0), H, key=11, width=42),
  ]
)

Regards,
Denes

Clemens

unread,
Nov 2, 2020, 4:40:50 PM11/2/20
to web2py-users
Could you please provide me an example PDF to see what the result should be?

DenesL

unread,
Nov 2, 2020, 5:20:48 PM11/2/20
to web2py-users
It would look something like the attached PDF.
pick_162323.pdf

Clemens

unread,
Nov 2, 2020, 7:41:55 PM11/2/20
to web2py-users
This is easy to build in LaTeX. There are a lot of introductions to LaTeX and TeX is easy to learn. Furthermore you will always find templates for your purpose. I think templates for an invoice would fit your demands. Just take one and adapt it. Then save it in template file to open and load in your python code. Just store the content in a string to replace placeholders for the date and so on. For the table with your list I would propose to generate it fully by python, because each row is just the values separated by ampersand (&).

When you have all done just call the TeX compiler as follows:
subprocess.Popen(['pdflatex', '-interaction', 'nonstopmode', '-output-directory={}'.format(output_dir), '{}/{}.tex'.format(output_dir, output_filename)])

And then as response return it as follows:
response.headers['Content-Type'] = 'application/pdf'
response.headers['Content-Disposition']='attachment;filename={}-REPORT-{}.pdf'.format(generation_date.strftime('%Y-%m-%d-%H%M%S'), title.replace(" ", "_"))

return response.stream('{}/{}.pdf'.format(output_dir, output_filename))

This way I'm producing large and well formatted reports (including table of contents and such things). I'm not using templates as proposed or generated by an WYSIWYG editor like LyX. I'm generating all the TeX code by Python. I think it depends on how familiar you are with LaTeX and how standardized your output is.

If you're going this way and you need assistance on a specific problem, please let me know. Or if you want to handle things more subtle (e.g. error handling of the TeX compiling), I can provide you more code snippets.

It's up to you to decide. I like TeXing my reports since there are no limits in formatting and everything you want to have in your report.

Regards
Clemens
Reply all
Reply to author
Forward
0 new messages