xero-python icon indicating copy to clipboard operation
xero-python copied to clipboard

Option for get_invoice_as_pdf to return the PDF as bytes

Open Sticky-Bits opened this issue 4 years ago • 3 comments

Hi, it would be really useful for us if accounting_api.get_invoice_as_pdf could return the PDF as bytes, instead of saving the file to /tmp/. At the moment our code looks roughly like:

filepath = accounting_api.get_invoice_as_pdf(tenant_id, invoice_id=uuid)
with open(filepath, 'rb') as f:
    pdf_bytes = f.read()
os.remove(filepath)
return pdf_bytes

And would be nice if we could instead do something like:

return accounting_api.get_invoice_as_pdf(tenant_id, invoice_id=uuid, pdf_as_bytes=True)

To avoid fetching the PDF, saving it to file, reading the file, deleting the file and then returning the bytes.

Sticky-Bits avatar Jun 30 '21 04:06 Sticky-Bits

it would be helpful if i know the location of the file in which this code is written.

deepgandhi avatar Feb 04 '22 06:02 deepgandhi

It would be also nice if we could instruct the function where to drop the file. Ie:

accounting_api.get_invoice_as_pdf(tenant_id, invoice_id=uuid, filename='/var/www/html/myapp/invoices/inv123.pdf')

PeterJointAU avatar May 17 '22 09:05 PeterJointAU