I want to concatenate two functions, thats all one, return a pdf.. and i want to show this 2 pages only in one
2017-01-13 23:02 GMT-02:00 Áureo Dias Neto <aureodiasn...@gmail.com>: > this is my all code of first page > i want another page, totally different of this, in the same pdf > > def ticketliberacao(): > from gluon.contrib.pyfpdf import FPDF, HTMLMixin > by_cdc_search = db(db.veiculos.CDC==request.args(0)).select(db.veiculos. > ALL).first() > if by_cdc_search.FlagSaida!=True: > redirect(URL('default', 'docs',args=('naoliberado'))) > > class MyFPDF(FPDF, HTMLMixin): > def header(self): > self.set_title("TICKET") > self.set_font('Arial', 'B', 11) > self.set_y(33) > self.cell(0, 0, "", 1, 0, 'L') > self.set_xy(10,40) > self.write(0,"TICKET DE LIBERAÇÃO".decode('utf-8')) > self.set_font('Arial', '', 11) > self.set_xy(144,40) > self.write(0,"Via do Responsável do veículo".decode('utf-8')) > logo = os.path.join(request.folder, "static", "images", "logo_patio.png") > self.image(logo, 10, 12) > logo = os.path.join(request.folder,"static", "images", > "logo_scov_preto.png") > self.image(logo, 150, 12) > > self.ln(10) > self.set_font('Arial', '', 13) > self.set_text_color(255,255,255) > self.cell(50,7,['CDC nº: '+by_cdc_search.CDC][-1]. > decode('utf-8'),1,0,'L',True) > cor=db(db.cores.id==by_cdc_search.Cor).select(db.cores.Cor).first() > self.cell(140,7,[by_cdc_search.MarcaModelo +' - '+ > cor.Cor][-1].decode('utf-8'),1,0,'R',True) > self.set_text_color(0,0,0) > self.ln(13) > liberadopara=db(db.pessoas.id==by_cdc_search.LiberadoPara). > select().first() > self.multi_cell(190,7,['Data da Liberação: > '+by_cdc_search.DataSaida.strftime("%d/%m/%Y")+' > - '+by_cdc_search.HoraSaida + '\nLiberado Por: '+by_cdc_search.LiberadoPor > + '\nLiberado Para: '+ '('+liberadopara.Tipo+') ' + liberadopara.Nome + > '\nChaves: '+by_cdc_search.Chaves+' | Vaga: '+by_cdc_search.Vaga][-1]. > decode('utf-8'),0,1,'L') > self.ln(13) > self.cell(110,7,['Observações da Saída:'][-1].decode('utf-8'),0,0,'L') > self.cell(80,7,['Confirmação da saída do pátio'][-1].decode('utf-8'),0, > 1,'L') > self.set_font('Arial','',8) > self.cell(90,7,['NÃO HÁ OBSERVAÇÕES' if by_cdc_search.ObservacoesSaida=='' > else by_cdc_search.ObservacoesSaida][-1].decode('utf-8'),0,1,'L') > self.set_x(120) > self.cell(80,7,['______________________________________'][-1].decode('utf-8'),0 > ,1,'L') > self.set_x(120) > self.set_font('Arial','',10) > self.cell(80,7,['Responsável da portaria'][-1].decode('utf-8'),0,0,'L') > self.ln(15) > self.write(0,'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > - - - - - - - - - - - - - - - - - - - -'.decode('utf-8')) > self.set_font('Arial', 'B', 11) > self.set_y(150) > self.ln(14) > self.cell(0, 0, "", 1, 0, 'L') > self.set_xy(10,170) > self.write(0,"TICKET DE LIBERAÇÃO".decode('utf-8')) > self.set_font('Arial', '', 11) > self.set_xy(170,170) > self.write(0,"Via do Pátio".decode('utf-8')) > logo = os.path.join(request.folder,"static", "images", "logo_patio.png") > self.image(logo, 10, 144) > logo = os.path.join(request.folder, "static", "images", > "logo_scov_preto.png") > self.image(logo, 150, 144) > > self.ln(10) > self.set_font('Arial', '', 13) > self.set_text_color(255,255,255) > self.cell(50,7,['CDC nº: '+by_cdc_search.CDC][-1]. > decode('utf-8'),1,0,'L',True) > cor=db(db.cores.id==by_cdc_search.Cor).select(db.cores.Cor).first() > self.cell(140,7,[by_cdc_search.MarcaModelo +' - '+ > cor.Cor][-1].decode('utf-8'),1,0,'R',True) > self.set_text_color(0,0,0) > self.ln(13) > self.multi_cell(190,7,['Data da Liberação: > '+by_cdc_search.DataSaida.strftime("%d/%m/%Y")+' > - '+by_cdc_search.HoraSaida + '\nLiberado Por: '+by_cdc_search.LiberadoPor > + '\nLiberado Para:'][-1].decode('utf-8'),0,1,'L') > liberadopara=db(db.pessoas.id==by_cdc_search.LiberadoPara). > select().first() > self.cell(190,7,['('+liberadopara.Tipo+') ' + > liberadopara.Nome][-1].decode('utf-8'),0,1,'L') > self.cell(190,7,['Chaves: '+by_cdc_search.Chaves+' | Vaga: > '+by_cdc_search.Vaga][-1].decode('utf-8'),0,0,'L') > self.ln(13) > self.cell(110,7,['Observações da Saída:'][-1].decode('utf-8'),0,1,'L') > self.set_font('Arial','',8) > self.cell(90,7,['NÃO HÁ OBSERVAÇÕES' if by_cdc_search.ObservacoesSaida=='' > else by_cdc_search.ObservacoesSaida][-1].decode('utf-8'),0,0,'L') > fotofrente=db(db.fotos.Veiculo.like(by_cdc_search.id) & > db.fotos.Tipo.like('Dianteira')).select().first() > if (fotofrente != None): > arquivo=fotofrente.Arquivo > fotolocal = os.path.join(request.folder, "uploads", arquivo) > self.image(fotolocal,120,190,80,50) > self.set_y(268) > self.set_font('Arial','',12) > self.cell(110,7,['_______________________________ > _____________________'][-1].decode('utf-8'),0,1,'L') > self.cell(110,1,['Responsável pela separação/entrega > Responsável do veículo'][-1].decode('utf-8'),0,1,'L') > > pdf = MyFPDF() > pdf.add_page() > response.headers['Content-Type'] = 'application/pdf' > return pdf.output(dest='S') > > > 2017-01-06 16:03 GMT-02:00 Edwood <edwood.oca...@gmail.com>: > >> It should work unless there is something in the HTML markup messing with >> the output. I tried this similar code with file output instead of stream >> and it did what you expected (as I understood it): >> >> from gluon.contrib.pyfpdf import FPDF, HTMLMixin >> from datetime import datetime >> >> class MyFPDF(FPDF, HTMLMixin): >> def header(self): >> self.set_title("Analise de Valores") >> self.set_font('Arial', '', 15) >> self.cell(0, 10, "title", 0, 0, 'L') >> self.cell(0, 10, '%s VEICULOS' % "50", 0, 0, 'R') >> self.line(287, 18, 10, 18) >> >> def footer(self): >> self.set_y(-15) >> self.set_font('Arial', 'I', 8) >> txt = 'Folha %s de %s' % (self.page_no(), self.alias_nb_pages()) >> self.cell(0, 10, txt, 0, 0, 'C') >> self.set_y(-15) >> self.set_font('Arial', 'I', 10) >> Useratual="auth.user" >> #Useratual = Useratual.first_name + ' ' + Useratual.last_name >> #Useratual = Useratual.decode("utf-8") >> data = datetime.now().strftime('%d/%m/%Y - %H:%M') >> self.cell(0, 20, 'Impresso por: %s (%s)' % (Useratual,"data"), 0, >> 0, 'C') >> >> pdf = MyFPDF('L') >> pdf.add_page('L') >> #pdf.write_html( str(XML(table, sanitize=True)).decode("utf-8")) >> >> # First page >> pdf.write_html('<h1>1st Page</h1>') >> pdf.write_html('<font size="9"><table><tr><th width="50%">1</th><th >> width="50%">2</th></tr><tbody><tr><td width="50%">TEST 1</td><td >> width="50%">TEST 2</td></tr><tr><td width="50%">TEST 3</td><td>TEST >> 4</td></tr></tbody><tfooter><tr><td width="50%">footer 1</td><td >> width="50%">footer 1</td></tr></tfooter></table></font>') >> >> # Second page >> pdf.add_page('L') >> pdf.write_html('<h1>2nd Page</h1>') >> pdf.write_html('<font size="15"><table><tr><th width="50%">10</th><th >> width="50%">20</th></tr><tbody><tr><td width="50%">TEST 5</td><td >> width="50%">TEST 6</td></tr><tr><td width="50%">TEST 7</td><td>TEST >> 8</td></tr></tbody><tfooter><tr><td width="50%">footer 2</td><td >> width="50%">footer 2</td></tr></tfooter></table></font>') >> >> # Third page >> pdf.add_page('L') >> pdf.write_html('<font size="15"><h1>3rd Page</h1></font>') >> pdf.write_html('<font size="15"><table><tr><th width="50%">100</th><th >> width="50%">200</th></tr><tbody><tr><td width="50%">TEST 9</td><td >> width="50%">TEST 10</td></tr><tr><td width="50%">TEST 11</td><td>TEST >> 12</td></tr></tbody><tfooter><tr><td width="50%">footer 3</td><td >> width="50%">footer 3</td></tr></tfooter></table></font>') >> #response.headers['Content-Type'] = 'application/pdf' >> pdf.output("multihtml.pdf", dest='F') >> >> I attached the PDF output (multihtml.pdf). Compare with your table's HTML. >> >> >> >> On Monday, January 2, 2017 at 9:53:24 PM UTC-4, Áureo Dias Neto wrote: >> >>> Hello, it's basically this: >>> >>> i want another page with another content, in the same function or >>> document pdf >>> >>> from gluon.contrib.pyfpdf import FPDF, HTMLMixin >>> >>> class MyFPDF(FPDF, HTMLMixin): >>> def header(self): >>> self.set_title("Analise de Valores") >>> self.set_font('Arial', '', 15) >>> self.cell(0, 10, response.title, 0, 0, 'L') >>> self.cell(0, 10, '%s VEICULOS' % registros, 0, 0, 'R') >>> self.line(287, 18, 10, 18) >>> >>> def footer(self): >>> self.set_y(-15) >>> self.set_font('Arial', 'I', 8) >>> txt = 'Folha %s de %s' % (self.page_no(), self.alias_nb_pages()) >>> self.cell(0, 10, txt, 0, 0, 'C') >>> self.set_y(-15) >>> self.set_font('Arial', 'I', 10) >>> Useratual=auth.user >>> Useratual = Useratual.first_name + ' ' + Useratual.last_name >>> Useratual = Useratual.decode("utf-8") >>> data = datetime.now().strftime('%d/%m/%Y - %H:%M') >>> self.cell(0, 20, 'Impresso por: %s (%s)' % (Useratual,data), 0, 0, 'C') >>> >>> pdf = MyFPDF('L') >>> pdf.add_page('L') >>> #pdf.write_html( str(XML(table, sanitize=True)).decode("utf-8")) >>> pdf.write_html('<font size="9">' + table.xml().decode('utf-8') + >>> '</font>') >>> pdf.add_page('L') >>> pdf.write_html('<font size="15">' + tabela_totais.xml().decode('utf-8') >>> + '</font>') >>> response.headers['Content-Type'] = 'application/pdf' >>> return pdf.output(dest='S') >>> >>> 2017-01-02 21:20 GMT-02:00 Edwood <edwood...@gmail.com>: >>> >>>> Happy new year to you too! >>>> >>>> Can you post the code? It will be easier to understand the problem. >>>> >>>> -- >>>> 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. >>>> >>> >>> -- >> 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+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.