Skip to main content

Quick Start

bkhtmltopdf delivers its service via HTTP, enabling you to convert HTML to PDF from anywhere.

cURL

Use cURL to send a request and save the response as a PDF file:

curl ‘http://localhost:8080/html-to-pdf’ \
-H ‘Content-Type: application/json’ \
--data-raw $‘{“html”:“<html><head><title>Blink HTML to PDF Example</title></head><body><h1>Hi,<a href=\'https://www.bkhtmltopdf.com\>bkhtmltopdf</a>.</h1></body></html>}' \
--output bkhtmltopdf.pdf

After running, bkhtmltopdf.pdf will be saved in the current directory. Open it with a PDF viewer to verify.

PowerShell

Send the request in PowerShell:

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
Invoke-WebRequest -UseBasicParsing -Uri “http://localhost:8080/html-to-pdf” `
-Method “POST” `
-WebSession $session `
-ContentType “application/json” `
-Body “{`”html`“:`”<!doctype html><html lang=\`“en\`”><head><title>Blink HTML to PDF Example</title></head><body><h1>Hi,<a href=\`“https://www.bkhtmltopdf.com\`”>bkhtmltopdf</a>.</h1></body></html>`“}
-OutFile “bkhtmltopdf.pdf”

The response will be saved as bkhtmltopdf.pdf.

Python (requests library)

Install requests (pip install requests), then run:

import requests
import json

url = “http://localhost:8080/html-to-pdf”
data = {
“html”:<html><head><title>Blink HTML to PDF Example</title></head><body><h1>Hi,<a href=‘https://www.bkhtmltopdf.com’>bkhtmltopdf</a>.</h1></body></html>
}

response = requests.post(url, json=data)
if response.status_code == 200:
with open(“bkhtmltopdf.pdf”, “wb”) as f:
f.write(response.content)
print(“PDF saved as bkhtmltopdf.pdf”)
else:
print(f“Error: {response.status_code})