View all our articles

Convert an HTML document to PDF from a URL in Python with requests

Converting HTML documents to PDFs using PDFShift's API is a straightforward process. With just a few lines of Python code, you can seamlessly convert a URL into a PDF document.

import requests

# You can get an API key at
api_key = 'sk_xxxxxxxxxxxx'

params = {
    'source': '',

response =
    auth=('api', api_key),

with open('result.pdf', 'wb') as f:

print('The PDF document was generated and saved to result.pdf')

With this Python script, you can effortlessly convert HTML documents from a URL to PDF files using PDFShift's API. Happy coding!

For further details on the source property and its usage, please refer to our dedicated documentation.

We hope this guide was helpful. If you have any questions or noticed any issues on the code above,
feel free to drop us a line.