Thank you José, this is strange because with 1.9.4 I have no problem.
This is the core part of the function: in the html view I have a link to 
generate the pdf.

## Before I create a table for html rendering
if request.extension=="pdf":
        import os
        from gluon.contrib.pyfpdf import FPDF, HTMLMixin

        # create a custom class with the required functionalities 
        class MyFPDF(FPDF, HTMLMixin):

            def header(self): 
                "hook to draw custom page header"
                
#logo=os.path.join(request.env.web2py_path,"applications","digitalcosting_3","static","images","g3001.png")
                
logo=os.path.join(request.env.web2py_path,request.folder,"static","images","g3001.png")
                self.image(logo,10,8,50)
                self.set_font('Arial','',12)
                self.cell(5) # padding
                #self.cell(60,10,"Rif. Preventivo n.12",0,0)
                self.ln(20)

            def footer(self):
                "hook to draw custom page header (printing page numbers)"
                self.set_y(-15)
                self.set_font('Helvetica','I',8)
                txt = 'Pagina %s of %s' % (self.page_no(), 
self.alias_nb_pages())
                self.cell(0,10,txt,0,0,'C')

        pdf=MyFPDF()
        pdf.set_top_margin(30)
        pdf.set_right_margin(10)
        pdf.set_font('times','',12)
        # create a page and serialize/render HTML objects
        pdf.add_page()
        txt="Rif. Preventivo n.%s"%(idprev,)
        txt_ana=mypdf[0].daticli
        txt_ana2=mycli[0].ragsoc
        txt_ana3=mycli[0].indirizzo
        txt_ana4=mycli[0].cap+" "+mycli[0].citta
        txt_data="Rasai, %s"%(myprev[0].data_prev.strftime("%d-%m-%Y"))
        txt_oggetto="Oggetto: "+ mypdf[0].oggetto
        txt_testo1=mypdf[0].testo1
        txt_testo2=mypdf[0].testo2
        txt_testo3=mypdf[0].testo3
        txt_testo4=mypdf[0].testo4
        consegna=mypdf[0].consegna
        pagamento=mypdf[0].pagamento+" "+pagam
        foot=mypdf[0].footer
        firma=mypdf[0].firma
        firma2=mypdf[0].firma2
        descrizione=unicode(myprev[0].descriz_est,'utf-8')
        descrizione=descrizione.encode('iso-8859-1')
        copie=myprev[0].copie_nom
        pr1="eur "+splitThousands(mylastprev[0].prezzo_off1)
        pr1t="eur "+splitThousands(mylastprev[0].pr_tot)
        #copie2=myprev[0].copie_nom2
        #pr2="eur "+splitThousands(mylastprev[0].prezzo_off2)
        #pr2t="eur "+splitThousands(mylastprev[0].pr_tot2)
        #copie3=myprev[0].copie_nom3
        #pr3="eur "+splitThousands(mylastprev[0].prezzo_off3)
        #pr3t="eur "+splitThousands(mylastprev[0].pr_tot3)
        pdf.cell(190,10,txt,0,1)
        pdf.cell(190,5,txt_ana,0,1,align="R")
        pdf.cell(190,5,txt_ana2,0,1,align="R")
        pdf.cell(190,5,txt_ana3,0,1,align="R")
        pdf.cell(190,5,txt_ana4,0,1,align="R")
        pdf.cell(190,10,txt_data,0,1,align="L")
        pdf.cell(190,10,txt_oggetto,0,1,align="L")
        pdf.ln(10)
        pdf.multi_cell(190,10,txt_testo1,0,align="L")
        pdf.ln(5)
        pdf.cell(100,10,"Descrizione",1,0,align="C")
        pdf.cell(30,10,"Qt Copie",1,0,align="C")
        pdf.cell(30,10,"Euro/Copia",1,0,align="C")
        pdf.cell(30,10,"Euro Totale",1,2,align="C")
        pdf.set_x(110)
        pdf.set_font_size(10)
        pdf.cell(30,10,copie,0,0,align="C")
        pdf.cell(30,10,pr1,0,0,align="C")
        pdf.cell(30,10,pr1t,0,1,align="R")
        if session.no_copie_alt !=True:
            pdf.set_x(110)
            pdf.cell(30,10,copie2,0,0,align="C")
            pdf.cell(30,10,pr2,0,0,align="C")
            pdf.cell(30,10,pr2t,0,1,align="R")
            pdf.set_x(110)
            pdf.cell(30,10,copie3,0,0,align="C")
            pdf.cell(30,10,pr3,0,0,align="C")
            pdf.cell(30,10,pr3t,0,1,align="R")
        pdf.set_xy(10,145)
        pdf.multi_cell(100,10,descrizione,0,align="L")
        pdf.set_xy(10,175)
        pdf.set_font('times','B',12)
        pdf.cell(190,5,txt_testo2,0,1,align="C")
        pdf.cell(190,5,txt_testo3,0,1,align="C")
        pdf.cell(190,5,txt_testo4,0,1,align="C")
        pdf.ln(5)
        pdf.set_font('times','',12)
        pdf.cell(190,10,consegna,0,1,align="L")
        pdf.cell(190,10,pagamento,0,1,align="L")
        pdf.multi_cell(190,10,foot,0,align="L")
        pdf.cell(190,10,firma,0,1,align="R")
        pdf.cell(190,10,firma2,0,1,align="R")



       
        # prepare PDF to download:
        response.headers['Content-Type']='application/pdf'
     
        return pdf.output(dest='S')
    else:
        # normal html view:
        return 
dict(table=table,mypdf=mypdf,mylastprev=mylastprev,myprev=myprev,mycli=mycli,pagam=pagam)



Il giorno giovedì 29 novembre 2012 13:45:08 UTC+1, José Luis Redrejo 
Rodríguez ha scritto:
>
> Hi Carlo
> I'm using fpdf without any problem, so I guess the reason is in some of 
> the data you're passing to fpdf.
> The code of the controller would be needed to can lend you a hand.
>
> Regards
>
>
> 2012/11/29 carlo <syse...@gmail.com <javascript:>>
>
>> No error with web2py 1.9.4.
>>
>> With 2.2.1 I got this with Python 2.5 and Python 2.6
>>
>>
>> Traceback (most recent call last):
>>   File "C:\Python25\web2py\gluon\restricted.py", line 212, in restricted
>>
>>
>>     exec ccode in environment
>>   File "C:/Python25/web2py/applications/Hcontrol/controllers/default.py" 
>> <http://127.0.0.1:8000/admin/default/edit/Hcontrol/controllers/default.py>, 
>> line 1000, in <module>
>>
>>
>>   File "C:\Python25\web2py\gluon\globals.py", line 188, in <lambda>
>>
>>
>>     self._caller = lambda f: f()
>>
>>
>>   File "C:/Python25/web2py/applications/Hcontrol/controllers/default.py" 
>> <http://127.0.0.1:8000/admin/default/edit/Hcontrol/controllers/default.py>, 
>> line 558, in pdf_prev
>>
>>
>>     pdf.add_page()
>>   File "C:\Python25\web2py\gluon\contrib\fpdf\fpdf.py", line 284, in add_page
>>
>>
>>     self.header()
>>   File "C:/Python25/web2py/applications/Hcontrol/controllers/default.py" 
>> <http://127.0.0.1:8000/admin/default/edit/Hcontrol/controllers/default.py>, 
>> line 540, in header
>>
>>
>>     self.image(logo,10,8,50)
>>
>>
>>   File "C:\Python25\web2py\gluon\contrib\fpdf\fpdf.py", line 896, in image
>>
>>
>>     info=self._parsepng(name)
>>
>>
>>   File "C:\Python25\web2py\gluon\contrib\fpdf\fpdf.py", line 1749, in 
>> _parsepng
>>
>>
>>     color += re.sub('(.{3}).',lambda m: m.group(1),line, flags=re.DOTALL)
>>
>> TypeError: sub() got an unexpected keyword argument 'flags'
>>
>>  -- 
>>  
>>  
>>  
>>
>
>

-- 



Reply via email to