Convert PDF Binary data to PDF File using python

151 Views Asked by At

I am hitting an API, from where I am receiving pdf file, When I try to convert the binary data received from API to PDF File using below.

resp = request.get(url=url) with open('test.pdf', 'wb') as pdffile: pdffile.write(resp.content)

However with this approach file is being save but data is incomplete. Also I am doing this on web application, I don't want to save the file on server, just wanna keep it in buffer memory and store it in a binary field.

Please let me know if anymore information is needed, I am using Odoo ERP system.

Thank you in Advance.

Binary Data Format starts with b'%PDF-1.6

1

There are 1 best solutions below

0
davyjonesx On

You might be able to use a BytesIO object

import io
with io.BytesIO(resp.content) as pdf_file:
#Do something with pdf_file