[reportlab-users] Another obscure error, this one regarding PDFPageLabel
Glenn Linderman
v+python at g.nevcal.com
Fri May 15 18:20:46 EDT 2015
Using PDFPageLabel, I accidentally defined two labels for the same
page. This resulted in the following stack trace...
doc.build( self.elements )
File
"C:\Python34\lib\site-packages\reportlab\platypus\doctemplate.py", line
916, in build
self._endBuild()
File
"C:\Python34\lib\site-packages\reportlab\platypus\doctemplate.py", line
858, in _endBuild
if getattr(self,'_doSave',1): self.canv.save()
File "C:\Python34\lib\site-packages\reportlab\pdfgen\canvas.py", line
1209, in save
self._doc.SaveToFile(self._filename, self)
File "C:\Python34\lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 217, in SaveToFile
data = self.GetPDFData(canvas)
File "C:\Python34\lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 242, in GetPDFData
return self.format()
File "C:\Python34\lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 421, in format
IOf = IO.format(self)
File "C:\Python34\lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 864, in format
fcontent = format(self.content, document, toplevel=1) # yes this
is at top level
File "C:\Python34\lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 78, in format
f = element.format(document)
File "C:\Python34\lib\site-packages\reportlab\pdfbase\pdfdoc.py",
line 1185, in format
self.labels.sort()
TypeError: unorderable types: PDFPageLabel() < PDFPageLabel()
The following adjustment to pdfdoc.py would improve the message. Maybe
the real problem is sorting by the whole tuple, instead of just using
the first element as the sort key, which seems to be what is expected to
happen.
class PDFPageLabels(PDFCatalog):
...
def format(self, document):
+ try:
self.labels.sort()
+ except TypeError:
+ raise TypeError("unorderable types PDFPageLabel. Likely
duplicate labels for same page number.")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist2.pair.net/pipermail/reportlab-users/attachments/20150515/93a439d2/attachment.html>
More information about the reportlab-users
mailing list