[Python-modules-team] Bug#571120: RFS: pisa/python-pisa

wjdoekes at osso.nl wjdoekes at osso.nl
Wed Jun 11 19:53:34 UTC 2014


> There has been some
> upstream changes, that should be reflected in the package.
> Mainly the name "pisa" is not used anymore, it seems, only
> "xhtml2pdf". The latest version is "0.0.4" at github [1]. But
> there was a release "0.0.6" at PyPI [2]. Is it based on the
> github code? Anyway, we should probably use the new version
> numbers with a new epoch and providing pisa. What do you think?

I did a quick test substituting:

   from ho.pisa import CreatePDF
   (python-pisa 3.0.32-1build1)

with this:

   from xhtml2pdf.pisa import CreatePDF
   (chrisglass gitrev 5987c9c9b3b04f55abb74fb2c4a82f023dc4268a
    Fri Jun 6 17:12:13 2014 +0800)

in a tiny example [1]. And the first thing I noticed is that
the xhtml2pdf version does not handle <td width=""> values like
expected [2].

I'd say patching sx.pisa3 with a tiny patch [3] is the quickest
fix to this bug. And that you cannot reasonably expect xhtml2pdf
to replace pisa without breaking things for a lot of people.


[1] Example code, comparing xhtml2pdf to ho/sx-pisa:

   from xhtml2pdf.pisa import CreatePDF as CreatePDF_xhtml2pdf, VERSION
   from ho.pisa import CreatePDF as CreatePDF_pisa, VERSION as VERSION2
   from io import BytesIO as S
   s = S('''
   <html>
           <head></head>
       <style>
           th, td { border:1pt solid black; border-collapse:collapse; }
           th { background: #ccc; }
       </style>
       <body>
           <table>
               <tr><th width="75%">75%</th><th>25%</th></tr>
               <tr><td>value</td><td>value</td></tr>
           </table>
       </body>
   </html>
   ''')
   s.seek(0)
   with open('xhtml2pdf.pdf', 'w') as d:
       print 'xhtml2pdf', VERSION
       CreatePDF_xhtml2pdf(src=s, dest=d)
   s.seek(0)
   with open('pisa.pdf', 'w') as d:
       print 'pisa', VERSION2
       CreatePDF_pisa(src=s, dest=d)


[2] The above script outputs this:

   xhtml2pdf 3.0.33
   pisa 3.0.32

And it writes two files:

   - xhtml2pdf.pdf
   - pisa.pdf

If you compare them, you see that the pisa.pdf renders the table like
expected with the first column taking up ~3/4 of the width. The
xhtml2pdf version makes the first column take up *less* than half
the width.


[3] Suggested fix: an improved version of [4]

   --- sx/pisa3/pisa_util.py.orig	2014-06-11 16:11:15.000000000 +0200
   +++ sx/pisa3/pisa_util.py	2014-06-11 20:57:19.557501000 +0200
   @@ -51,10 +51,11 @@ import shutil

    rgb_re = re.compile("^.*?rgb[(]([0-9]+).*?([0-9]+).*?([0-9]+)[)].*?[ 
]*$")

   -if not(reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"):
   +_reportlab_version = tuple(map(int, reportlab.Version.split('.')))
   +if _reportlab_version < (2, 1):
        raise ImportError("Reportlab Version 2.1+ is needed!")

   -REPORTLAB22 = (reportlab.Version[0] == "2" and reportlab.Version[2] 
 >= "2")
   +REPORTLAB22 = _reportlab_version >= (2, 2)
    # print "***", reportlab.Version, REPORTLAB22, reportlab.__file__

    import logging


[4] http://anonscm.debian.org/viewvc/python-modules/packages/pisa/\
   trunk/debian/patches/0002-Fix-reportlab-version-detection-for-\
   versions-greater.patch?view=markup


Cheers,
Walter Doekes
OSSO B.V.



More information about the Python-modules-team mailing list