Monday, November 30 2026

How to generate a PDF from JSON

Essau Ramirez@essau

How to generate a print-ready PDF from a structured JSON layout (or from Markdown, HTML, and interactive fillable forms) using the webprint API.

import requests

url = "https://webprint.p.rapidapi.com/pdf/json"

payload = {
	"version": "1.0",
	"filename": "invoice-1042.pdf",
	"metadata": {
		"title": "Invoice #1042",
		"author": "Acme Studio LLC"
	},
	"page": {
		"size": "A4",
		"orientation": "portrait",
		"unit": "mm",
		"margins": { "top": 20, "right": 15, "bottom": 20, "left": 15 }
	},
	"footer": {
		"height": 12,
		"elements": [
			{
				"type": "text",
				"text": "Page {{page}} of {{totalPages}}",
				"align": "right"
			}
		]
	},
	"elements": [
		{
			"type": "heading",
			"level": 1,
			"text": "ACME STUDIO"
		},
		{
			"type": "text",
			"text": "Invoice #INV-2026-1042 — Date: {{date}}"
		},
		{
			"type": "table",
			"headerBackground": "#1E293B",
			"stripeColor": "#F9FAFB",
			"columns": [
				{ "width": "3*", "align": "left" },
				{ "width": 20, "align": "right" },
				{ "width": 30, "align": "right" },
				{ "width": 35, "align": "right" }
			],
			"headerRows": [
				{
					"cells": [
						{ "text": "Description", "style": { "color": "#FFFFFF", "bold": true } },
						{ "text": "Qty", "style": { "color": "#FFFFFF", "bold": true } },
						{ "text": "Unit Price", "style": { "color": "#FFFFFF", "bold": true } },
						{ "text": "Total", "style": { "color": "#FFFFFF", "bold": true } }
					]
				}
			],
			"rows": [
				{
					"cells": [
						{ "text": "Cloud PDF Rendering Subscription" },
						{ "text": "1" },
						{ "text": "$499.00" },
						{ "text": "$499.00" }
					]
				}
			]
		}
	]
}

# insert your API_KEY
headers = {
	"x-rapidapi-key": "[API_KEY]",
	"x-rapidapi-host": "webprint.p.rapidapi.com",
	"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

with open("invoice-1042.pdf", "wb") as f:
	f.write(response.content)

This script returns the binary PDF document (Content-Type: application/pdf) and saves it to invoice-1042.pdf.

You can also generate PDFs from Markdown (POST /pdf/json), HTML & CSS (POST /pdf/json), or add interactive fillable AcroForm fields (text, textarea, select, checkbox, radio, date, and signature) using "type": "formField":

{
  "filename": "onboarding-form.pdf",
  "elements": [
    {
      "type": "heading",
      "level": 1,
      "text": "Customer Onboarding Form"
    },
    {
      "type": "formField",
      "fieldType": "text",
      "name": "company_name",
      "label": "Company Name",
      "value": "Northwind Traders",
      "required": true
    },
    {
      "type": "formField",
      "fieldType": "checkbox",
      "name": "accept_terms",
      "label": "I agree to the Master Services Agreement",
      "checked": true
    }
  ]
}

Sign up at RapidAPI|webprint to get your API_KEY.