On Monday, May 16, 2016 at 1:49:55 PM UTC-7, Dragan Matic wrote:
>
> 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.
>
> If you prefer to maintain an MVC style, my sample at
<URL:https://groups.google.com/d/msg/web2py/fio15y9n2EU/95223fifCgAJ>
approaches that, and also shows using a ROWS object if your project
requires results from one of your tables.
/dps
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.