Hello, I am using the qrcode library to generate a qr code and then display
it in a pdf. For this I use the fpdf library but when I pass the image it
shows me the following error:
<type 'exceptions.RuntimeError'> FPDF error: Unsupported image type: pdf
Here I show you the method to generate the qr code:
*def generarQr(): qr = qrcode.QRCode( version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10, border=4, ) qr.add_data('940830-cod')
qr.make(fit=True) img = qr.make_image(fill_color="black",
back_color="white") response.headers['Content-Type'] = "image/png"
img.save(response.body, "PNG") return response.body.getvalue()*
And this is the code that exports to pdf:
*def crearPdf(): response.title = "Testing qr" url = URL(r=request,
f='generarQr.html') imagen = IMG(_src=URL(r=request, f='generarQr'),
_width="100", _height="100") # define header and footers: head =
THEAD(TR(TH("Header 1", _width="50%"), TH("Header 2",
_width="50%"), # TH("Header 3",
_width="20%"), _bgcolor="#A0A0A0")) foot =
TFOOT(TR(TH("Footer 1", _width="50%"), TH("Footer 2",
_width="50%"), # TH("Footer 3",
_width="20%"), _bgcolor="#E0E0E0")) # create several
rows: rows = [] for i in range(5): col = i % 2 and "#F0F0F0"
or "#FFFFFF" rows.append(TR(TD("Row %s" % i),
TD(imagen, _align="center"), _bgcolor=col)) #
TD("%s" % i, _align="right"), # make the table object body =
TBODY(*rows) table = TABLE(*[head, foot, body],
_border="1", _align="center", _width="100%") if request.extension ==
"pdf": # from gluon.contrib.pyfpdf import FPDF, HTMLMixin #
define our FPDF class (move to modules if it is reused frequently)
class MyFPDF(FPDF, HTMLMixin): def header(self):
self.set_font('Arial', 'B', 15) self.cell(0, 10,
response.title, 1, 0, 'C') self.ln(20) def
footer(self): self.set_y(-15)
self.set_font('Arial', 'I', 8) txt = 'Page %s of %s' %
(self.page_no(), self.alias_nb_pages()) self.cell(0, 10,
txt, 0, 0, 'C') pdf = MyFPDF() # first page:
pdf.add_page() #the error is here pdf.write_html(str(XML(table,
sanitize=False))) response.headers['Content-Type'] =
'application/pdf' return pdf.output(dest='S') else: #
normal html view: return dict(table=table)*Please i need help!!!!
--
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.