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": 1,
"templatedata": "{\"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.\"}",
"margins": "10px 10px 10px 10px",
"papersize": "A4",
"orientation": "Portrait",
"printbackground": true,
"mediatype": "print",
"donotwaitfullload": false,
"header": "<string>",
"footer": "<string>",
"legacyrendition": true,
"name": "multipagedInvoiceWithQRCode.pdf",
"async": false,
"expiration": 60,
"profiles": "<string>"
}
'import requests
url = "https://api.pdf.co/v1/pdf/convert/from/html"
payload = {
"html": "<string>",
"templateid": 1,
"templatedata": "{\"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.\"}",
"margins": "10px 10px 10px 10px",
"papersize": "A4",
"orientation": "Portrait",
"printbackground": True,
"mediatype": "print",
"donotwaitfullload": False,
"header": "<string>",
"footer": "<string>",
"legacyrendition": True,
"name": "multipagedInvoiceWithQRCode.pdf",
"async": False,
"expiration": 60,
"profiles": "<string>"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
html: '<string>',
templateid: 1,
templatedata: '{"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."}',
margins: '10px 10px 10px 10px',
papersize: 'A4',
orientation: 'Portrait',
printbackground: true,
mediatype: 'print',
donotwaitfullload: false,
header: '<string>',
footer: '<string>',
legacyrendition: true,
name: 'multipagedInvoiceWithQRCode.pdf',
async: false,
expiration: 60,
profiles: '<string>'
})
};
fetch('https://api.pdf.co/v1/pdf/convert/from/html', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pdf.co/v1/pdf/convert/from/html",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'html' => '<string>',
'templateid' => 1,
'templatedata' => '{"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."}',
'margins' => '10px 10px 10px 10px',
'papersize' => 'A4',
'orientation' => 'Portrait',
'printbackground' => true,
'mediatype' => 'print',
'donotwaitfullload' => false,
'header' => '<string>',
'footer' => '<string>',
'legacyrendition' => true,
'name' => 'multipagedInvoiceWithQRCode.pdf',
'async' => false,
'expiration' => 60,
'profiles' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pdf.co/v1/pdf/convert/from/html"
payload := strings.NewReader("{\n \"html\": \"<string>\",\n \"templateid\": 1,\n \"templatedata\": \"{\\\"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.\\\"}\",\n \"margins\": \"10px 10px 10px 10px\",\n \"papersize\": \"A4\",\n \"orientation\": \"Portrait\",\n \"printbackground\": true,\n \"mediatype\": \"print\",\n \"donotwaitfullload\": false,\n \"header\": \"<string>\",\n \"footer\": \"<string>\",\n \"legacyrendition\": true,\n \"name\": \"multipagedInvoiceWithQRCode.pdf\",\n \"async\": false,\n \"expiration\": 60,\n \"profiles\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.pdf.co/v1/pdf/convert/from/html")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"html\": \"<string>\",\n \"templateid\": 1,\n \"templatedata\": \"{\\\"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.\\\"}\",\n \"margins\": \"10px 10px 10px 10px\",\n \"papersize\": \"A4\",\n \"orientation\": \"Portrait\",\n \"printbackground\": true,\n \"mediatype\": \"print\",\n \"donotwaitfullload\": false,\n \"header\": \"<string>\",\n \"footer\": \"<string>\",\n \"legacyrendition\": true,\n \"name\": \"multipagedInvoiceWithQRCode.pdf\",\n \"async\": false,\n \"expiration\": 60,\n \"profiles\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pdf.co/v1/pdf/convert/from/html")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"html\": \"<string>\",\n \"templateid\": 1,\n \"templatedata\": \"{\\\"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.\\\"}\",\n \"margins\": \"10px 10px 10px 10px\",\n \"papersize\": \"A4\",\n \"orientation\": \"Portrait\",\n \"printbackground\": true,\n \"mediatype\": \"print\",\n \"donotwaitfullload\": false,\n \"header\": \"<string>\",\n \"footer\": \"<string>\",\n \"legacyrendition\": true,\n \"name\": \"multipagedInvoiceWithQRCode.pdf\",\n \"async\": false,\n \"expiration\": 60,\n \"profiles\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"message": "Success",
"url": "https://pdf-temp-files.s3.us-west-2.amazonaws.com/output.pdf",
"jobId": "6YSZD3U872ZYYFEDMQCQSGEEO8YSF5WA",
"credits": 2,
"remainingCredits": 1480582,
"duration": 33
}{
"error": true,
"status": 400,
"message": "Bad request. Typically due to bad input parameters or unreachable input URLs (e.g., access restrictions like login or password)."
}{
"error": true,
"status": 401,
"message": "Unauthorized. Authentication is required and has failed or has not yet been provided."
}{
"error": true,
"status": 402,
"message": "Not enough credits."
}{
"error": true,
"status": 403,
"message": "Access forbidden for input URL."
}{
"error": true,
"status": 404,
"message": "The requested resource could not be found."
}{
"error": true,
"status": 408,
"message": "The server timed out waiting for the request."
}{
"error": true,
"status": 429,
"message": "Too many requests in a given time period."
}{
"error": true,
"status": 441,
"message": "Invalid Password. Password protected document."
}{
"error": true,
"status": 442,
"message": "Input document is damaged or of incorrect type."
}{
"error": true,
"status": 443,
"message": "Permissions. The operation is prohibited by document security settings."
}{
"error": true,
"status": 444,
"message": "Profiles parsing error. Please ensure that the configuration is supported."
}{
"error": true,
"status": 445,
"message": "Timeout error. For large documents, use asynchronous mode (async=true) and check status via /job/check."
}{
"error": true,
"status": 446,
"message": "Some files required for conversion are missing."
}{
"error": true,
"status": 447,
"message": "Invalid template."
}{
"error": true,
"status": 448,
"message": "Invalid URL or HTML. Ensure the provided URL is valid and accessible."
}{
"error": true,
"status": 449,
"message": "Invalid index range. Page index is out of range."
}{
"error": true,
"status": 450,
"message": "Invalid page range specified."
}{
"error": true,
"status": 452,
"message": "Invalid URL."
}{
"error": true,
"status": 454,
"message": "Invalid parameters."
}{
"error": true,
"status": 500,
"message": "Something went wrong. Please try again or contact support."
}PDF from HTML (API Tester)
Run PDF from HTML live from your browser — send a real request and see the response and credit usage, no code required. PDF.co API Tester.
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": 1,
"templatedata": "{\"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.\"}",
"margins": "10px 10px 10px 10px",
"papersize": "A4",
"orientation": "Portrait",
"printbackground": true,
"mediatype": "print",
"donotwaitfullload": false,
"header": "<string>",
"footer": "<string>",
"legacyrendition": true,
"name": "multipagedInvoiceWithQRCode.pdf",
"async": false,
"expiration": 60,
"profiles": "<string>"
}
'import requests
url = "https://api.pdf.co/v1/pdf/convert/from/html"
payload = {
"html": "<string>",
"templateid": 1,
"templatedata": "{\"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.\"}",
"margins": "10px 10px 10px 10px",
"papersize": "A4",
"orientation": "Portrait",
"printbackground": True,
"mediatype": "print",
"donotwaitfullload": False,
"header": "<string>",
"footer": "<string>",
"legacyrendition": True,
"name": "multipagedInvoiceWithQRCode.pdf",
"async": False,
"expiration": 60,
"profiles": "<string>"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
html: '<string>',
templateid: 1,
templatedata: '{"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."}',
margins: '10px 10px 10px 10px',
papersize: 'A4',
orientation: 'Portrait',
printbackground: true,
mediatype: 'print',
donotwaitfullload: false,
header: '<string>',
footer: '<string>',
legacyrendition: true,
name: 'multipagedInvoiceWithQRCode.pdf',
async: false,
expiration: 60,
profiles: '<string>'
})
};
fetch('https://api.pdf.co/v1/pdf/convert/from/html', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pdf.co/v1/pdf/convert/from/html",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'html' => '<string>',
'templateid' => 1,
'templatedata' => '{"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."}',
'margins' => '10px 10px 10px 10px',
'papersize' => 'A4',
'orientation' => 'Portrait',
'printbackground' => true,
'mediatype' => 'print',
'donotwaitfullload' => false,
'header' => '<string>',
'footer' => '<string>',
'legacyrendition' => true,
'name' => 'multipagedInvoiceWithQRCode.pdf',
'async' => false,
'expiration' => 60,
'profiles' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pdf.co/v1/pdf/convert/from/html"
payload := strings.NewReader("{\n \"html\": \"<string>\",\n \"templateid\": 1,\n \"templatedata\": \"{\\\"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.\\\"}\",\n \"margins\": \"10px 10px 10px 10px\",\n \"papersize\": \"A4\",\n \"orientation\": \"Portrait\",\n \"printbackground\": true,\n \"mediatype\": \"print\",\n \"donotwaitfullload\": false,\n \"header\": \"<string>\",\n \"footer\": \"<string>\",\n \"legacyrendition\": true,\n \"name\": \"multipagedInvoiceWithQRCode.pdf\",\n \"async\": false,\n \"expiration\": 60,\n \"profiles\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.pdf.co/v1/pdf/convert/from/html")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"html\": \"<string>\",\n \"templateid\": 1,\n \"templatedata\": \"{\\\"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.\\\"}\",\n \"margins\": \"10px 10px 10px 10px\",\n \"papersize\": \"A4\",\n \"orientation\": \"Portrait\",\n \"printbackground\": true,\n \"mediatype\": \"print\",\n \"donotwaitfullload\": false,\n \"header\": \"<string>\",\n \"footer\": \"<string>\",\n \"legacyrendition\": true,\n \"name\": \"multipagedInvoiceWithQRCode.pdf\",\n \"async\": false,\n \"expiration\": 60,\n \"profiles\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pdf.co/v1/pdf/convert/from/html")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"html\": \"<string>\",\n \"templateid\": 1,\n \"templatedata\": \"{\\\"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.\\\"}\",\n \"margins\": \"10px 10px 10px 10px\",\n \"papersize\": \"A4\",\n \"orientation\": \"Portrait\",\n \"printbackground\": true,\n \"mediatype\": \"print\",\n \"donotwaitfullload\": false,\n \"header\": \"<string>\",\n \"footer\": \"<string>\",\n \"legacyrendition\": true,\n \"name\": \"multipagedInvoiceWithQRCode.pdf\",\n \"async\": false,\n \"expiration\": 60,\n \"profiles\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"status": "success",
"message": "Success",
"url": "https://pdf-temp-files.s3.us-west-2.amazonaws.com/output.pdf",
"jobId": "6YSZD3U872ZYYFEDMQCQSGEEO8YSF5WA",
"credits": 2,
"remainingCredits": 1480582,
"duration": 33
}{
"error": true,
"status": 400,
"message": "Bad request. Typically due to bad input parameters or unreachable input URLs (e.g., access restrictions like login or password)."
}{
"error": true,
"status": 401,
"message": "Unauthorized. Authentication is required and has failed or has not yet been provided."
}{
"error": true,
"status": 402,
"message": "Not enough credits."
}{
"error": true,
"status": 403,
"message": "Access forbidden for input URL."
}{
"error": true,
"status": 404,
"message": "The requested resource could not be found."
}{
"error": true,
"status": 408,
"message": "The server timed out waiting for the request."
}{
"error": true,
"status": 429,
"message": "Too many requests in a given time period."
}{
"error": true,
"status": 441,
"message": "Invalid Password. Password protected document."
}{
"error": true,
"status": 442,
"message": "Input document is damaged or of incorrect type."
}{
"error": true,
"status": 443,
"message": "Permissions. The operation is prohibited by document security settings."
}{
"error": true,
"status": 444,
"message": "Profiles parsing error. Please ensure that the configuration is supported."
}{
"error": true,
"status": 445,
"message": "Timeout error. For large documents, use asynchronous mode (async=true) and check status via /job/check."
}{
"error": true,
"status": 446,
"message": "Some files required for conversion are missing."
}{
"error": true,
"status": 447,
"message": "Invalid template."
}{
"error": true,
"status": 448,
"message": "Invalid URL or HTML. Ensure the provided URL is valid and accessible."
}{
"error": true,
"status": 449,
"message": "Invalid index range. Page index is out of range."
}{
"error": true,
"status": 450,
"message": "Invalid page range specified."
}{
"error": true,
"status": 452,
"message": "Invalid URL."
}{
"error": true,
"status": 454,
"message": "Invalid parameters."
}{
"error": true,
"status": 500,
"message": "Something went wrong. Please try again or contact support."
}Body
please set to string converted from JSON with data for Mustache template or leave empty if no template is used
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.
"10px 10px 10px 10px"
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'.
Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 "A4"
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
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 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.
Response
Success.
Was this page helpful?