Skip to content Skip to sidebar Skip to footer

Pdf Response Is Corrupted In Python 3 But Works In Python 2

I wrote a working application in python2.7 and Flask. One of the things it does is download a PDF invoice. It's working fine. Now I am doing a new app that also allows downloading

Solution 1:

FPDF outputs a str which in Python 2 is basically equivalent to bytes, but in Python 3 is unicode, not bytes. Straight from the docs:

If you are using Python 3.x you have to use pdf.output(dest='S').encode('latin-1') in order to get the output, if you don't do so the generated PDF will be invalid

Post a Comment for "Pdf Response Is Corrupted In Python 3 But Works In Python 2"