Another obscure error, this one regarding PDFPageLabel

Glenn Linderman <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <[email protected]>
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.")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.