How to convert HTML to PDF Using DocRaptor?
In Python DocRaptor allows you to convert HTML document to PDF.
Do you have similar website/ Product?
Show in this page just for only
$2 (for a month)
0/60
0/180
Open the given link and install the DocRaptor:
For installation use pip type :
pip install docraptor:
To create PDF from HTML document is quite simple you have to post your HTML to DocRaptor and you will get the response as text or plain.
import docraptor
docraptor.configuration.username = "YOUR_KEY_HERE" doc_api = docraptor.DocApi() response = doc_api.create_doc({ "test":True,"document_url":"https://docraptor.com/documentation/api", "name": "docraptor-python.pdf", "document_type": "pdf", }) with open('output.pdf', "wb") as f: f.write(response) |
If you want to generate PDFs asynchronously:
import docraptor
import time docraptor.configuration.username = "API_KEY" doc_api = docraptor.DocApi() try: create_response = doc_api.create_async_doc ({ "test": True, "document_url": "https://docraptor.com/documentation/api", "name": "docraptor-python.pdf", "document_type": "pdf", "javascript": }) while True: status_response=doc_api.get_async_doc_status(create_response.status_id) if status_response.status == "completed": doc_response=doc_api.get_async_doc(status_response.download_id) file = open("./docraptor-python.pdf", "wb") file.write(doc_response) file.close print("Wrote PDF docraptor-python.pdf to current working directory") break elif status_response.status == "failed": print("FAILED") print(status_response) break else: time.sleep(1) except docraptor.rest.ApiException as error: print(error) print(error.message) print(error.code) print(error.response_body) |
CONTINUE READING
DocRaptor
Ayesha
Tech writer at newsandstory