[reportlab-users] Problems generating PDFs with drawText()

66 views
Skip to first unread message

Marius Flage

unread,
Dec 14, 2014, 8:17:23 AM12/14/14
to reportl...@lists2.reportlab.com
Hi!

I wrote a small script to generate invoices from GNUCash with reportlab,
but haven't been able to use it for the last couple of years. Firstly
because an error with the drawOn and Table methods which outputted
nothing. After an upgrade to the latest version of reportlab, then
tabular data started working again and I could use these methods again,
but now drawText() has stopped working. drawString() works fine, but
drawText() outputs nothing in the PDF document.

Here's my code:

from reportlab.lib.units import mm
from reportlab.lib import colors
from reportlab.lib.pagesizes import A4
from reportlab.pdfgen import canvas
from reportlab.platypus import *
from reportlab.rl_config import defaultPageSize
from reportlab.lib.styles import getSampleStyleSheet

c = canvas.Canvas("test.pdf", A4)

# company information
text = c.beginText()
text.setTextOrigin(150*mm, 282*mm)
text.textLines("""test dwkmflwkmfw
telkmtlwkmtw
tlkmewltmwt""")
c.drawText(text)

c.showPage()
c.save()

---------

But test.pdf is empty. Any idea? I'm running the latest version of
reportlab as installed from pip install reportlab.

- Marius
_______________________________________________
reportlab-users mailing list
reportl...@lists2.reportlab.com
https://pairlist2.pair.net/mailman/listinfo/reportlab-users

Adrian Klaver

unread,
Dec 14, 2014, 9:44:03 AM12/14/14
to reportlab-users
No idea. I can confirm though that the above works in 2.7 but not in 3.1.8

>
> - Marius



--
Adrian Klaver
adrian...@aklaver.com

Marius Flage

unread,
Dec 14, 2014, 4:08:44 PM12/14/14
to reportl...@lists2.reportlab.com
Your answer did at least lead me to downgrade to 2.7 and then both
approaches worked - both Table() and drawText().

Thanks, I guess :)

- Marius

Andy Robinson

unread,
Dec 14, 2014, 4:14:27 PM12/14/14
to reportlab-users
Marius, are you talking about ReportLab 2.7/3.x, or Python 2.7/3.x?

Either way if there is a bug here we will look into it tomorrow morning.

- Andy Robinson
--
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420

Marius Flage

unread,
Dec 14, 2014, 4:15:44 PM12/14/14
to reportl...@lists2.reportlab.com
I'm talking about Reportlab. For several versions Table() didn't work,
and when I then upgraded to Ubuntu Trusty 14.04.1, then the Table() was
working again, but drawText() wasn't. Downgrading to 2.7 solved both
problems.

- Marius

Andy Robinson

unread,
Dec 14, 2014, 4:52:09 PM12/14/14
to reportlab-users
I can see this on my machine too. Since all of our numerous test
documents "look normal", I can only presume we have changed the way we
use textobjects and not documented the new way clearly enough. I
cannot investigate properly tonight but we'll look at this in the
morning and get back to you tomorrow.

- Andy
--
Andy Robinson
Managing Director
ReportLab Europe Ltd.
Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK
Tel +44-20-8405-6420

Robin Becker

unread,
Dec 15, 2014, 5:43:26 AM12/15/14
to reportlab-users
On 14/12/2014 21:52, Andy Robinson wrote:
> I can see this on my machine too. Since all of our numerous test
> documents "look normal", I can only presume we have changed the way we
> use textobjects and not documented the new way clearly enough. I
> cannot investigate properly tonight but we'll look at this in the
> morning and get back to you tomorrow.
>
> - Andy

Well I just tested the sample script on windows with python2.7/3.3/3.4 and it
seems to work for all. The pdfs produced are effectively identical (at least
when RL_invariant=1).

I will try the same on linux.
>
> On 14 December 2014 at 21:15, Marius Flage <mar...@flage.org> wrote:
>> I'm talking about Reportlab. For several versions Table() didn't work,
>> and when I then upgraded to Ubuntu Trusty 14.04.1, then the Table() was
>> working again, but drawText() wasn't. Downgrading to 2.7 solved both
>> problems.
>>
>> - Marius
>>
..........
--
Robin Becker

Robin Becker

unread,
Dec 15, 2014, 6:37:15 AM12/15/14
to reportlab-users
On 14/12/2014 21:52, Andy Robinson wrote:
> I can see this on my machine too. Since all of our numerous test
> documents "look normal", I can only presume we have changed the way we
> use textobjects and not documented the new way clearly enough. I
> cannot investigate properly tonight but we'll look at this in the
> morning and get back to you tomorrow.
>
> - Andy


The problem appears to be present in 3.1.8, but not in latest code. It seems it
was fixed by"textobject.py: fix bug in textlines contributed by Andrey Khomenko
@ bitbucket.org".
--
Robin Becker

Robin Becker

unread,
Dec 15, 2014, 8:18:32 AM12/15/14
to reportlab-users
On 14/12/2014 13:17, Marius Flage wrote:
> Hi!
>
> I wrote a small script to generate invoices from GNUCash with reportlab, but
> haven't been able to use it for the last couple of years. Firstly because an
> error with the drawOn and Table methods which outputted nothing. After an
> upgrade to the latest version of reportlab, then tabular data started working
> again and I could use these methods again, but now drawText() has stopped
> working. drawString() works fine, but drawText() outputs nothing in the PDF
> document.
........
Marius, this should now be fixed if you want to try the latest version from pypi.
--
Robin Becker
Reply all
Reply to author
Forward
0 new messages