ERPNext Conference 2019* ERPNext.com Blog

Downloading PDF Files by REST API is it good decison?


#1

I find the best way to download doctype’s pdf file on my local machine. Is exist any way to do it?

I have my part of code:

for item in items:
    url = "http://" + frappe.request.host + "/api/method/frappe.utils.print_format.download_pdf?doctype=Certificate&name=" + \
          item['name'] + \
          "&format=New Horizons Certificate&no_letterhead=0"
    doc = get_pdf(url)
    with open('file.pdf','wb') as file:
        file.write(doc)

When I opened my “file.pdf” as html page, I got error:
image

How I can download pdf file on my server? Is it correct way or what I make wrong?


#2

Good Day

I also looking for backend mine in php to download pdf and download to user pc.
Did you manage to get this working?