import Sudopdf from '@sudopdf/sdk';
const client = new Sudopdf({
apiKey: 'My API Key', // process.env['SUDOPDF_API_KEY'] is the default and can be omitted.
});
const response = await client.pdf.generate({
templateId: 22
data: { foo: 'bar' }
});
console.log(response.data);curl --request POST \
--url http://app.sudopdf.com/api/v1/pdf/generate \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"data": {},
"templateId": "<string>",
"url": "<string>",
"html": "<string>",
"metadata": {},
"renderOptions": {
"path": "<string>",
"scale": 1,
"displayHeaderFooter": true,
"headerTemplate": "<string>",
"footerTemplate": "<string>",
"printBackground": true,
"landscape": true,
"pageRanges": "<string>",
"width": "<string>",
"height": "<string>",
"margin": {
"top": "<string>",
"right": "<string>",
"bottom": "<string>",
"left": "<string>"
},
"preferCSSPageSize": true,
"timeout": 123,
"omitBackground": true
}
}
'import requests
url = "http://app.sudopdf.com/api/v1/pdf/generate"
payload = {
"data": {},
"templateId": "<string>",
"url": "<string>",
"html": "<string>",
"metadata": {},
"renderOptions": {
"path": "<string>",
"scale": 1,
"displayHeaderFooter": True,
"headerTemplate": "<string>",
"footerTemplate": "<string>",
"printBackground": True,
"landscape": True,
"pageRanges": "<string>",
"width": "<string>",
"height": "<string>",
"margin": {
"top": "<string>",
"right": "<string>",
"bottom": "<string>",
"left": "<string>"
},
"preferCSSPageSize": True,
"timeout": 123,
"omitBackground": True
}
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "http://app.sudopdf.com/api/v1/pdf/generate",
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([
'data' => [
],
'templateId' => '<string>',
'url' => '<string>',
'html' => '<string>',
'metadata' => [
],
'renderOptions' => [
'path' => '<string>',
'scale' => 1,
'displayHeaderFooter' => true,
'headerTemplate' => '<string>',
'footerTemplate' => '<string>',
'printBackground' => true,
'landscape' => true,
'pageRanges' => '<string>',
'width' => '<string>',
'height' => '<string>',
'margin' => [
'top' => '<string>',
'right' => '<string>',
'bottom' => '<string>',
'left' => '<string>'
],
'preferCSSPageSize' => true,
'timeout' => 123,
'omitBackground' => true
]
]),
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 := "http://app.sudopdf.com/api/v1/pdf/generate"
payload := strings.NewReader("{\n \"data\": {},\n \"templateId\": \"<string>\",\n \"url\": \"<string>\",\n \"html\": \"<string>\",\n \"metadata\": {},\n \"renderOptions\": {\n \"path\": \"<string>\",\n \"scale\": 1,\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"printBackground\": true,\n \"landscape\": true,\n \"pageRanges\": \"<string>\",\n \"width\": \"<string>\",\n \"height\": \"<string>\",\n \"margin\": {\n \"top\": \"<string>\",\n \"right\": \"<string>\",\n \"bottom\": \"<string>\",\n \"left\": \"<string>\"\n },\n \"preferCSSPageSize\": true,\n \"timeout\": 123,\n \"omitBackground\": true\n }\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("http://app.sudopdf.com/api/v1/pdf/generate")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"data\": {},\n \"templateId\": \"<string>\",\n \"url\": \"<string>\",\n \"html\": \"<string>\",\n \"metadata\": {},\n \"renderOptions\": {\n \"path\": \"<string>\",\n \"scale\": 1,\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"printBackground\": true,\n \"landscape\": true,\n \"pageRanges\": \"<string>\",\n \"width\": \"<string>\",\n \"height\": \"<string>\",\n \"margin\": {\n \"top\": \"<string>\",\n \"right\": \"<string>\",\n \"bottom\": \"<string>\",\n \"left\": \"<string>\"\n },\n \"preferCSSPageSize\": true,\n \"timeout\": 123,\n \"omitBackground\": true\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://app.sudopdf.com/api/v1/pdf/generate")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"data\": {},\n \"templateId\": \"<string>\",\n \"url\": \"<string>\",\n \"html\": \"<string>\",\n \"metadata\": {},\n \"renderOptions\": {\n \"path\": \"<string>\",\n \"scale\": 1,\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"printBackground\": true,\n \"landscape\": true,\n \"pageRanges\": \"<string>\",\n \"width\": \"<string>\",\n \"height\": \"<string>\",\n \"margin\": {\n \"top\": \"<string>\",\n \"right\": \"<string>\",\n \"bottom\": \"<string>\",\n \"left\": \"<string>\"\n },\n \"preferCSSPageSize\": true,\n \"timeout\": 123,\n \"omitBackground\": true\n }\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"mode": "sync",
"message": "PDF generated successfully",
"environment": "production",
"data": {
"url": "https://app.sudopdf.com/files/abc123.pdf",
"creditsUsed": 1
}
}Generate PDF
Generate a single PDF
import Sudopdf from '@sudopdf/sdk';
const client = new Sudopdf({
apiKey: 'My API Key', // process.env['SUDOPDF_API_KEY'] is the default and can be omitted.
});
const response = await client.pdf.generate({
templateId: 22
data: { foo: 'bar' }
});
console.log(response.data);curl --request POST \
--url http://app.sudopdf.com/api/v1/pdf/generate \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: <api-key>' \
--data '
{
"data": {},
"templateId": "<string>",
"url": "<string>",
"html": "<string>",
"metadata": {},
"renderOptions": {
"path": "<string>",
"scale": 1,
"displayHeaderFooter": true,
"headerTemplate": "<string>",
"footerTemplate": "<string>",
"printBackground": true,
"landscape": true,
"pageRanges": "<string>",
"width": "<string>",
"height": "<string>",
"margin": {
"top": "<string>",
"right": "<string>",
"bottom": "<string>",
"left": "<string>"
},
"preferCSSPageSize": true,
"timeout": 123,
"omitBackground": true
}
}
'import requests
url = "http://app.sudopdf.com/api/v1/pdf/generate"
payload = {
"data": {},
"templateId": "<string>",
"url": "<string>",
"html": "<string>",
"metadata": {},
"renderOptions": {
"path": "<string>",
"scale": 1,
"displayHeaderFooter": True,
"headerTemplate": "<string>",
"footerTemplate": "<string>",
"printBackground": True,
"landscape": True,
"pageRanges": "<string>",
"width": "<string>",
"height": "<string>",
"margin": {
"top": "<string>",
"right": "<string>",
"bottom": "<string>",
"left": "<string>"
},
"preferCSSPageSize": True,
"timeout": 123,
"omitBackground": True
}
}
headers = {
"X-API-KEY": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "http://app.sudopdf.com/api/v1/pdf/generate",
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([
'data' => [
],
'templateId' => '<string>',
'url' => '<string>',
'html' => '<string>',
'metadata' => [
],
'renderOptions' => [
'path' => '<string>',
'scale' => 1,
'displayHeaderFooter' => true,
'headerTemplate' => '<string>',
'footerTemplate' => '<string>',
'printBackground' => true,
'landscape' => true,
'pageRanges' => '<string>',
'width' => '<string>',
'height' => '<string>',
'margin' => [
'top' => '<string>',
'right' => '<string>',
'bottom' => '<string>',
'left' => '<string>'
],
'preferCSSPageSize' => true,
'timeout' => 123,
'omitBackground' => true
]
]),
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 := "http://app.sudopdf.com/api/v1/pdf/generate"
payload := strings.NewReader("{\n \"data\": {},\n \"templateId\": \"<string>\",\n \"url\": \"<string>\",\n \"html\": \"<string>\",\n \"metadata\": {},\n \"renderOptions\": {\n \"path\": \"<string>\",\n \"scale\": 1,\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"printBackground\": true,\n \"landscape\": true,\n \"pageRanges\": \"<string>\",\n \"width\": \"<string>\",\n \"height\": \"<string>\",\n \"margin\": {\n \"top\": \"<string>\",\n \"right\": \"<string>\",\n \"bottom\": \"<string>\",\n \"left\": \"<string>\"\n },\n \"preferCSSPageSize\": true,\n \"timeout\": 123,\n \"omitBackground\": true\n }\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("http://app.sudopdf.com/api/v1/pdf/generate")
.header("X-API-KEY", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"data\": {},\n \"templateId\": \"<string>\",\n \"url\": \"<string>\",\n \"html\": \"<string>\",\n \"metadata\": {},\n \"renderOptions\": {\n \"path\": \"<string>\",\n \"scale\": 1,\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"printBackground\": true,\n \"landscape\": true,\n \"pageRanges\": \"<string>\",\n \"width\": \"<string>\",\n \"height\": \"<string>\",\n \"margin\": {\n \"top\": \"<string>\",\n \"right\": \"<string>\",\n \"bottom\": \"<string>\",\n \"left\": \"<string>\"\n },\n \"preferCSSPageSize\": true,\n \"timeout\": 123,\n \"omitBackground\": true\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://app.sudopdf.com/api/v1/pdf/generate")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"data\": {},\n \"templateId\": \"<string>\",\n \"url\": \"<string>\",\n \"html\": \"<string>\",\n \"metadata\": {},\n \"renderOptions\": {\n \"path\": \"<string>\",\n \"scale\": 1,\n \"displayHeaderFooter\": true,\n \"headerTemplate\": \"<string>\",\n \"footerTemplate\": \"<string>\",\n \"printBackground\": true,\n \"landscape\": true,\n \"pageRanges\": \"<string>\",\n \"width\": \"<string>\",\n \"height\": \"<string>\",\n \"margin\": {\n \"top\": \"<string>\",\n \"right\": \"<string>\",\n \"bottom\": \"<string>\",\n \"left\": \"<string>\"\n },\n \"preferCSSPageSize\": true,\n \"timeout\": 123,\n \"omitBackground\": true\n }\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"mode": "sync",
"message": "PDF generated successfully",
"environment": "production",
"data": {
"url": "https://app.sudopdf.com/files/abc123.pdf",
"creditsUsed": 1
}
}Authorizations
Query Parameters
Whether to generate the PDF synchronously. Not recomended for production use
Body
PDF to generate
Any data that use inside the template. Prefer metadata if you are not planning to use that data inside template
Unique Id of your template you like to render
You can pass a url directly and get the webpage rendered.
Data associated with this render but not used inside template.
Advanced rendering options for PDF generation
Show child attributes
Show child attributes
Response
PDF generation response
Unified PDF generation success response
Indicates if the request was successful
true
Response mode - sync for immediate PDF generation, async for background processing
sync, async Human-readable summary of the response
"PDF generated successfully"
Data payload for synchronous PDF generation
- Option 1
- Option 2
Show child attributes
Show child attributes
Environment where the PDF was generated
development, production