Add ability to download receipts in PDF form

This commit is contained in:
Joseph Schorr 2013-11-18 14:49:54 -05:00
parent f8ae8ed6cd
commit 4c6012f756
4 changed files with 47 additions and 6 deletions

View file

@ -1,5 +1,7 @@
from datetime import datetime
from jinja2 import Environment, FileSystemLoader
from xhtml2pdf import pisa
import StringIO
jinja_options = {
"loader": FileSystemLoader('util'),
@ -7,6 +9,20 @@ jinja_options = {
env = Environment(**jinja_options)
def renderInvoiceToPdf(invoice, user):
""" Renders a nice PDF display for the given invoice. """
sourceHtml = renderInvoiceToHtml(invoice, user)
output = StringIO.StringIO()
pisaStatus = pisa.CreatePDF(sourceHtml, dest=output)
if pisaStatus.err:
return None
value = output.getvalue()
output.close()
return value
def renderInvoiceToHtml(invoice, user):
""" Renders a nice HTML display for the given invoice. """
def get_price(price):