Render integration quickstart

To begin your integration process, sign up by clicking here and then retrieve your API key.

Send HTML content to Render

Now that you have your API key, you'll need to store it securely and grant access only to those who need it. We recommend setting the API key as an environment variable:

export INKIT_API_KEY='YOUR_API_KEY'
export INKIT_API_KEY='YOUR_API_KEY'
setx INKIT_API_KEY "YOUR_API_KEY"

Choose your favorite language, then copy and paste the code into your environment. This snippet will convert your document.

# Pre Req - run this command: pip install requests

import base64
import requests
import os
import json

endpoint = "https://api.inkit.com"
your_api_key = os.environ.get("INKIT_API_KEY")

html_data = "<html>Hello World :)</html>"
render_unit = "in"
render_width = 8.5
render_height = 11

# uncomment the below to use a file on your local machine
#with open("your_input_file.html", "r") as f:
#    html_data = f.read()

base64_html = base64.b64encode(html_data.encode("utf-8")).decode("utf-8")

headers = {
    "X-Inkit-API-Token": your_api_key,
    "Content-Type": "application/json"
}

json_data = {
    "html": base64_html,
    "unit": render_unit,
    "width": render_width,
    "height": render_height
}

r = requests.post(f"{endpoint}/v1/render",
    data=json.dumps(json_data),
    headers=headers)

print(f"Your render id is: {r.json().get ('id')}")

Get the resulting render id and run this snippet to retrieve your PDF content.

# Pre Req - run this command: pip install requests

import base64
import requests
import os

endpoint = "https://api.inkit.com" 
your_api_key = os.environ.get("INKIT_API_KEY")


rend_id = "Your render id from the previous request"
file_name = "inkit_render_get_started.pdf"

headers = {
 "X-Inkit-API-Token": your_api_key
}

r = requests.get(f"{endpoint}/v1/render/{rend_id}/pdf"
    , headers=headers)

with open(file_name, "wb") as f:
    f.write(r.content)

print (f"Your pdf is saved in this file: {file_name}")

You've officially converted and retrieved your first PDF document. Hurray! You can find the PDF in the directory where your code is saved.


Did this page help you?