Rendering PDF issues - rendered file looks differently each time

444 views
Skip to first unread message

Michał Gajek

unread,
Apr 5, 2013, 7:11:54 AM4/5/13
to xhtm...@googlegroups.com
Hi,
so I've started using xhtml2pdf yesterday. I had some really simple html code which I would like to render to pdf for testing purposes.

I've found out that calling the pisa.CreatePDF with the same file as input results in a  PDF file which is a bit different each time I call the pisa.CreatePDF

for testing purposes I have this simple Python program:

#!/usr/bin/env python
from xhtml2pdf import pisa
import StringIO

lastlen = 0
def helloWorld(i):
    global lastlen
    filename = __file__ + ".pdf"
    strobj = StringIO.StringIO()
    with open('rep.html') as f:
        pdf = pisa.CreatePDF(
            f.read(),
            strobj)
    different = lastlen != strobj.len
    if different:
        with open('rep_%d.pdf' % i, 'wb') as f:
            strobj.seek(0)
            f.write(strobj.buf)

    print "len\t%d\t%s" % (strobj.len, '!!' if different else '')
    lastlen = strobj.len
        #file(filename, "wb"))


and here is the example result:

len     3279    !!
len     3285    !!
len     3279    !!
len     3273    !!
len     3279    !!
len     2382    !!
len     3279    !!
len     3291    !!
len     3285    !!
len     3295    !!


and there are some screenshots of the PDF files:






and there's the pip freeze result:

Pillow==2.0.0
argparse==1.2.1
html5lib==0.95
pyPdf==1.13
reportlab==2.7
wsgiref==0.1.2
xhtml2pdf==0.0.5


any suggestion WHY THE HELL is the resulting file different each time?!


Daniel Pelegrini

unread,
Apr 30, 2013, 11:35:09 AM4/30/13
to xhtm...@googlegroups.com
I'm having this problem as well. Have you solved your problem?

Does somebody else knows what's the issue?

Thanks,

Daniel Pelegrini

Michał Gajek

unread,
May 2, 2013, 8:03:09 AM5/2/13
to xhtm...@googlegroups.com
Hi,
I've solved the problem by moving to weasyprint ( http://weasyprint.org/ ). it has pretty proper support of CSS properties, but first of all it just WORKS.

Best regards,
Michal Gajek

Dirk Holtwick

unread,
May 2, 2013, 8:40:16 AM5/2/13
to xhtm...@googlegroups.com
Hi Michael,

Thanks for sharing, this project looks awesome! I have updated the "Alternatives" section accordingly: http://www.xhtml2pdf.com/

You need to consider, that xhtml2pdf development has been started almost 10 years ago and that most HTML and CSS features didn't even exist at that time. Also the availability of third party libraries that help parsing HTML and creating PDF has become much better nowadays. 

But xhtml2pdf has also proved to work reliable in production environments and porting is easy since it is written in pure Python and hasn't very much dependencies.

Anyway it's great to see that there are other Python projects that work on HTML to PDF conversion. I still believe in the basic idea of leveraging common HTML knowledge to create flexible PDF output. Those two worlds deserve a good links in form of a good tools :)

Cheers,
Dirk

--
You received this message because you are subscribed to the Google Groups "Pisa XHTML2PDF Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xhtml2pdf+...@googlegroups.com.
To post to this group, send email to xhtm...@googlegroups.com.
Visit this group at http://groups.google.com/group/xhtml2pdf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michał Gajek

unread,
May 3, 2013, 7:48:21 AM5/3/13
to xhtm...@googlegroups.com
Hello Dirk,

I fully understand the limitations of xhtml2pdf and their reasons, moreover I find the xhtml2pdf better for my needs - less dependencies (this is the VERY big downside of weasyprint), but unfortunately - the issue described in the first post here made me to look for alternatives. It seems that this is not the problem of my particular configuration, as Daniel seems to have the same problem./ 

Hope to see that fixed so I can switch back to xhtml2pdf for lightweight PDF generation.

Best regards,
Michal

john christensen

unread,
Jun 17, 2013, 7:58:22 PM6/17/13
to xhtm...@googlegroups.com
PDF issues can be solved by the use of how to repair damaged pdf file

Guilherme Vierno

unread,
Nov 21, 2013, 7:39:32 AM11/21/13
to xhtm...@googlegroups.com
Downgrading to version 0.0.4 fixed this for me, hope it helps someone.


Em sexta-feira, 5 de abril de 2013 08h11min54s UTC-3, Michał Gajek escreveu:
Reply all
Reply to author
Forward
0 new messages