[reportlab-users] ValueError: redefining named object
jo
jose.soares at sferacarta.com
Mon Feb 18 11:54:59 EST 2008
Robin Becker ha scritto:
> jo wrote:
>> My propose is to print more than one page in the same document.
>> Infact the error is not raised if my pdf is only one page.
>> Probably there's something that I am doing wrong. :-\
>>
>> I changed a little your sample to having it printing two pages.
>> It prints the first page without errors,
>> but the second time...
>> ValueError: redefining named object:
>> 'toUnicodeCMap:SUBSET+OCRB10PitchBT-Regular+0'
>
> I'm afraid your email has messed up all indentation so I cannot tell
> where the def page actually ends, but if the page function contains a
> canv.save then that is being done twice, on the other hand if it's
> outside the function then the canv.save will cause an error because
> canv is not defined. However, putting the canv.save in the right place
> make this work just fine. The canv.save() finishes the canvas off and
> writes stuff to disk etc etc. I'm not surprised you get errors writing
> to a defunct canvas. Probably all accesses should be made illegal
> after that, but that's quite difficult and probably not worth the
> effort; besides a small number of experts might want to inspect the
> canvas object even after its 'gone away' or 'turned its toes up' or
> 'taken out Norwegian citizen ship' :)
>
> ##################
> from reportlab.pdfgen import canvas
> from reportlab.pdfbase import pdfmetrics, ttfonts
> pdfmetrics.registerFont(ttfonts.TTFont("Rina", "rina.ttf"))
> def page(line1,line2):
> t=canv.beginText(72,72)
> t.setFont('Rina',10)
> t.setFillColor((1,0,0))
> t.textOut('hello')
> t.setFont('Rina',12)
> t.setFillColor((0,1,0))
> t.textOut(line1)
> t.setFont('Rina',8)
> t.setFillColor((0,0,1))
> t.textOut(line2)
> canv.drawText(t)
> canv.showPage()
>
> canv = canvas.Canvas('out.pdf')
> page(line1='cruel',line2='world') #page 1
> page(line1='wonderful',line2='world') #page 2
> canv.save()
> ##################
>
> ............
You are right Robin, I was writing to a defunct canvas. :-[
Now it works, thank you very much,
jo
More information about the reportlab-users
mailing list