[reportlab-users] Tried reportlab on python 3.4... failed
Glenn Linderman
v+python at g.nevcal.com
Sat Oct 25 15:52:20 EDT 2014
On 10/25/2014 12:01 AM, Glenn Linderman wrote:
> Since reportlab was one of a very few reasons I have python 2.7
> installed, I have watched with anticipation the development of
> reportlab for python 3. Today I decided to try it, because I tried to
> operate on a file with a non-ASCII character in it, and python 2.7
> doesn't like those, so rather than rename the file, I installed
> reportlab in Python 3.4.1 via pip. The install seemed to go fine.
>
> I tweaked the launching of my PDF generator to launch it via Python
> 3.4.1 instead of python 2.7. Since it has been a while since I looked
> at that code, I figured I would get a bunch of Python 2->3 sort of
> errors, but... not yet...
>
> Instead, on the call to mkdoc(), I got a traceback, from mkdoc() down
> here it is:
>
> in mkdoc:
> doc.build( elements, onFirstPage=mkpage )
> File
> "c:\python34\lib\site-packages\reportlab\platypus\doctemplate.py",
> line 1127, in build
> BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
> File
> "c:\python34\lib\site-packages\reportlab\platypus\doctemplate.py",
> line 8 90, in build
> self.handle_flowable(flowables)
> File
> "c:\python34\lib\site-packages\reportlab\platypus\doctemplate.py",
> line 773, in handle_flowable
> if frame.add(f, canv, trySplit=self.allowSplitting):
> File "c:\python34\lib\site-packages\reportlab\platypus\frames.py",
> line 161, in _add
> w, h = flowable.wrap(aW, h)
> File
> "c:\python34\lib\site-packages\reportlab\platypus\paragraph.py", line
> 1035, in wrap
> blPara = self.breakLines([first_line_width, later_widths])
> File
> "c:\python34\lib\site-packages\reportlab\platypus\paragraph.py", line
> 1203, in breakLines
> splitLongWords = style.splitLongWords
> AttributeError: 'MyParaSt' object has no attribute 'splitLongWords'
>
>
> The definition for MyParaSt is as follows... works fine in reportlab
> 2.5 on python 2.7....
>
> class MyParaSt(PropertySet):
> defaults = {
> 'fontName': 'Times-New-Roman',
> 'fontSize': defsize,
> 'leading': deflead,
> 'leftIndent': 0,
> 'rightIndent': 0,
> 'firstLineIndent': 0,
> 'alignment': TA_LEFT,
> 'spaceBefore': 0,
> 'spaceAfter': 0,
> 'bulletFontName': 'Times-New-Roman',
> 'bulletFontSize': 10,
> 'bulletIndent': 0,
> 'textColor': black,
> 'backColor': None,
> 'wordWrap': None,
> 'borderWidth': 0,
> 'borderPadding': 0,
> 'borderColor': None,
> 'borderRadius': None,
> 'allowWidows': 1,
> 'allowOrphans': 0,
> 'textTransform': None,
> #uppercase lowercase (captitalize not yet) or None or absent
> }
>
> I'm not exactly sure why I have a MyParaSt, since it has been a long
> time since I wrote this, but I would guess it might have been to set
> the default font(s)? Maybe there would have been a better way, like
> only changing the items I wanted to change, rather than creating my
> whole new own defaults hash? I probably cut-n-pasted this idea from
> somewhere, though, and maybe it wasn't the best idea?
So I found the latest user guide, and in chapter six it shows something
just like this:
class ParagraphStyle(PropertySet):
defaults = {
'fontName':'Times-Roman',
'fontSize':10,
'leading':12,
'leftIndent':0,
'rightIndent':0,
'firstLineIndent':0,
'alignment':TA_LEFT,
'spaceBefore':0,
'spaceAfter':0,
'bulletFontName':'Times-Roman',
'bulletFontSize':10,
'bulletIndent':0,
'textColor': black,
'backColor':None,
'wordWrap':None,
'borderWidth': 0,
'borderPadding': 0,
'borderColor': None,
'borderRadius': None,
'allowWidows': 1,
'allowOrphans': 0,
}
(indentation didn't survive the paste from the PDF file). And there is
no sign of splitLongWords here, either... but I see that the things I
might have changed were the fontSize & leading. Not sure where I got
'textTransform': None, or the uppercase comment, but... no doubt
somewhere...
Anyway, in the spirit of "programming by guessing", I added
'splitLongWords': 0,
to my definition. It got further, I guess, and complained similarly
that endDots was not defined, so without additional research, I added
'endDots': 0,
and then the program ran. So it seems that these items should either be
added to the example in the user guide, since they seem to be necessary,
or perhaps their necessity should be removed by checking their existence
before referencing them, and using some default if they do not exist.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20141025/455de241/attachment.html>
More information about the reportlab-users
mailing list