Skip to main content
POST
/
v1
/
pdf
/
convert
/
from
/
html
PDF from HTML
curl --request POST \
  --url https://api.pdf.co/v1/pdf/convert/from/html \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "html": "<string>",
  "templateid": 123,
  "templatedata": "<string>",
  "margins": "10px 10px 10px 10px",
  "papersize": "A4",
  "orientation": "Portrait",
  "printbackground": true,
  "mediatype": "print",
  "donotwaitfullload": false,
  "header": "<string>",
  "footer": "<string>",
  "legacyrendition": true,
  "name": "<string>",
  "async": true,
  "expiration": 60,
  "profiles": "<string>"
}'

Authorizations

x-api-key
string
header
required

Body

application/json
html
string
required

HTML code.

templateid
number
default:1
required

Set ID of HTML template to be used. View and manage your templates at HTML to PDF Templates.

templatedata
string
default:{"paid":true,"invoice_id":"0021","invoice_date":"August 29, 2041","invoice_dateDue":"September 29, 2041","issuer_name":"Sarah Connor","issuer_company":"T-800 Research Lab","issuer_address":"435 South La Fayette Park Place, Los Angeles, CA 90057","issuer_website":"www.example.com","issuer_email":"info@example.com","client_name":"Cyberdyne Systems","client_company":"Cyberdyne Systems","client_address":"18144 El Camino Real, Sunnyvale, California","client_email":"sales@example.com","items":[{"name":"T-800 Prototype Research","price":1000.0},{"name":"T-800 Cloud Sync Setup","price":300.0}],"discount":0.1,"tax":0.0725,"note":"Thank you for your support of advanced robotics."}

please set to string converted from JSON with data for Mustache template or leave empty if no template is used

margins
string<{topMargin} {rightMargin} {bottomMargin} {leftMargin}>
default:40px 20px 20px 20px

Set custom margins, overriding CSS default margins. Specify the margins in the format {top} {right} {bottom} {left}. You can usepx,mm,cmorinunits. Also, you can set margins for all sides at once using a single value.

Example:

"10px 10px 10px 10px"

papersize
default:A4

Specifies the paper size. Accepts standard sizes like 'Letter', 'Legal', 'Tabloid', 'Ledger', 'A0'–'A6'. You can also set a custom size by providing width and height separated by a space, with optional units: px (pixels), mm (millimeters), cm (centimeters), or in (inches). Examples: '200 300', '200px 300px', '200mm 300mm', '20cm 30cm', '6in 8in'.

Available options:
Letter,
Legal,
Tabloid,
Ledger,
A0,
A1,
A2,
A3,
A4,
A5,
A6
Example:

"A4"

orientation
enum<string>
default:Portrait

Sets the document orientation. Options: Portrait for vertical layout, and Landscape for horizontal layout.

Available options:
Portrait,
Landscape
printbackground
boolean
default:true

Set to false to disable background colors and images are included when generating PDFs from HTML/URL

mediatype
enum<string>
default:print

Controls how content is rendered when converting to PDF. Options: print (uses print styles), screen (uses screen styles), none (no media type applied).

Available options:
print,
screen,
none
donotwaitfullload
boolean
default:false

Controls how thoroughly the converter waits for a page to load before converting HTML to PDF --- false waits for full page load, while true speeds up conversion by waiting only for minimal loading.

header
string<html>

Set this to can add user definable HTML for the header to be applied on every page header. The format is html.

Set this to can add user definable HTML for the footer to be applied on every page bottom. The format is html.

legacyrendition
boolean

use legacy rendition (optional)

name
string
default:multipagedInvoiceWithQRCode.pdf

File name for generated output.

async
boolean
default:false

Set async to true for long processes to run in the background, API will then return a jobId which you can use with the Background Job Check endpoint. Also see Webhooks & Callbacks

expiration
number
default:60

Sets the expiration time for the output link, in minutes. After this period, generated output file(s) are automatically deleted from PDF.co Temporary Files Storage. The maximum allowed duration depends on your subscription plan. For permanent storage of input files (e.g., reusable images, PDF templates, documents), use PDF.co Built‑In Files Storage.

profiles
string

Profiles are used configure extra options for specific API endpoints and may be unique to an API. For more information, see Profiles and the documentation of each endpoint for profiles specific to it.