#render
5
min read

How to Create PDF from HTML and Retrieve It with Python

Learn how to convert HTML files to PDF using Python programming language and retrieve the generated documents. Guidelines for Inkit Render.

Inkit Render HTML to PDF converter integrates with applications written in multiple languages. The Python programming language is one of them. Using Python, you can programmatically convert HTML file to PDF and then retrieve it for further use.

Python is at the core of many types of applications, including data analytics systems, web applications, financial solutions, etc. It makes Python support a valuable feature of Render HTML to PDF converter.

This tutorial will explain how to convert HTML files to PDF and retrieve them with Python using Inkit Render.

Start with API Settings

Before converting HTML strings to PDF files, you need to connect Render’s API to your existing software.

To initiate the integration, click this link. It opens the registration page where you can join Inkit using your Google, GitHub, and Microsoft account or email.

After the registration, start the configuration to convert HTML markup language to PDF. You need to get your API key, store it, and select the language you want to use for conversion. In our case, it’s Python.

How to Create PDF from HTML Using Python

To create PDF from HTML using Python, you need to:

  1. Go to the Render’s Create page.
  2. Select Python as the programming language to convert your HTML file to PDF.
  3. Once you select the language, the code snippet on the right is automatically provided for Python. It will look the following way:


import requests


url = "https://api.inkit.com/v1/render"


payload = {

   "html": "PGh0bWw+dGVzdCAgPC9odG1sPg==",

   "unit": "in",

   "width": 8.5,

   "height": 11

}

headers = {"Content-Type": "application/json"}


response = requests.request("POST", url, json=payload, headers=headers)


print(response.text)


  1. Customize body parameters if you want to change the standard PDF format before you create PDF from HTML.


  1. Indicate your unique API key in the X-Inkit-API-Token field.
  2. Copy the snippet and paste it into your environment to create PDF from HTML.

How to Retrieve the Generated PDF Using Python

After creating a PDF file from the HTML web page, you can keep it in storage or retrieve and use it. Retrieved PDFs can be sent by email, printed and mailed, or published online.

To retrieve the PDF documents after you create PDF from HTML, you need to:

  1. Go to the Render’s Retrieve PDF page.
  2. Select Python as the programming language to have the snippet properly formatted. It will look like this:

import requests


url = "https://api.inkit.com/v1/render/renderId/pdf"


headers = {"Accept": "application/pdf"}


response = requests.request("GET", url, headers=headers)


print(response.text)



  1. Indicate your Render ID in the Path parameters.
  2. Enter your unique API key in the X-Inkit-API-Token field.
  3. Copy and paste the Python snippet into your environment to retrieve the Python HTML to PDF conversion.

How to Retrieve the Metadata About the Python HTML to PDF Conversion

Apart from retrieving the result of Python HTML to PDF conversion, you can retrieve metadata about the converted PDF. The Retrieve request is a separate type of API request supported by Inkit for this.

Retrieve allows you to obtain information about the converted files and the rendering instance. You can use it similarly to Create and Retrieve PDF requests: Go to the Retrieve page > Select Python > Customize the parameters > Copy and run the snippet to retrieve the metadata about Python HTML to PDF conversion.

Everything Else You Need to Know About Render HTML to PDF Converter

Inkit Render is an HTML to PDF converter API provided by Inkit. Unlike online tools that require manual document rendering, Render enables you to layer HTML page to PDF generation into existing software. After a quick integration, rendering capabilities become an indispensable part of your solutions.

In addition to Python HTML to PDF conversion, Render supports other programming languages. Therefore, you can integrate Render with almost any type of app. Render’s user roles and rich functionality help you ensure granular access to confidential data and security in your software.

For Frequently Asked Questions about Inkit Render and the list of Inkit Render plans, go here. Contact us to get Render’s demo and learn more about how it works in our tutorials.

up next