The PDFGate API provides a collection of simple HTTP endpoints for working with PDF files. You can generate PDFs from HTML or URLs, create fillable form fields, flatten or extract data from existing PDFs, and apply watermarks or security settings. Each endpoint is designed to be fast, reliable, and easy to integrate into your applications.
All API requests to PDFGate must be authenticated using an API key. Authentication is handled via the Authorization header in your HTTP requests.
To get started, log in to your PDFGate account and create an API key from the Settings page in the dashboard. Ensure the key is active before using it in your code.
Include the API key in your request headers like this:
Authorization: Bearer YOUR_API_KEYPDFGate supports two types of API keys:
Use sandbox keys for testing purposes and production keys in your live environment.
The PDFGate API uses different rate limits for each account type in the production environment. In the sandbox environment, the rate limits are the same for all account types.
| Endpoint | Production | Sandbox |
|---|---|---|
POST /v1/generate/pdf POST /forms/flatten POST /forms/extract-data POST /watermark/pdf POST /protect/pdf POST /compress/pdf | Per account type:
| Per account type:
|
GET /document | 40 concurrent requests | 10 concurrent requests |
GET /file | 40 concurrent requests | 10 concurrent requests |
| Code | Error |
|---|---|
| 400 | Bad request |
| 401 | Unauthorized |
| 404 | Not found |
| 422 | Unprocessable entity |
| 429 | Too many requests |
| 500 | Internal server error |
To create a PDF document, send either a URL or raw HTML in the request body. Include your API key in the headers and set the appropriate Content-Type.
By default, the endpoint returns a raw PDF file. If you prefer a structured response, you can include the jsonResponse field in your request to receive a JSON payload with metadata about the generated document.
Endpoint
Examples
const fetch = require("node-fetch");
const fs = require("fs");
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
url: "https://en.wikipedia.org/wiki/PDF",
pageSizeType: "a4",
}),
};
fetch("https://api.pdfgate.com/v1/generate/pdf", options).then( async (result) => {
if (result.status === 201) {
result.body.pipe(fs.createWriteStream("file_name.pdf"));
} else {
const error = await result.json();
console.log(error);
}
});
Request body fields
"1-5" or "1,3,5". If not specified, all pages are included.Available responses
The Flatten PDF endpoint converts an interactive PDF (with fillable form fields or annotations) into a static, non-editable version.
documentId referencing an existing file already stored in our database.If a documentId is provided, the API will always create a new flattened file in the database, rather than overwriting the existing one.
In this case, the response includes a derivedFrom parameter (when jsonResponse is set to true), it indicates the original document ID from which the flattened file was created.
Endpoint
Examples
const fs = require("fs/promises");
(async () => {
const form = new FormData();
const bytes = await fs.readFile("YOUR_FILE.pdf");
const file = new File([bytes], "YOUR_FILE.pdf", { type: "application/pdf" });
form.append("file", file);
form.append("jsonResponse", "false");
form.append("metadata", JSON.stringify({
author: "John Doe",
documentType: "Contract",
}));
const res = await fetch("https://api.pdfgate.com/forms/flatten", {
method: "POST",
body: form,
headers: { Authorization: "Bearer YOUR_API_KEY" },
});
if (res.status === 201) {
const buf = Buffer.from(await res.arrayBuffer());
await fs.writeFile("flattened.pdf", buf);
} else {
const text = await res.text();
console.error(text);
}
})();
Request body fields
.pdfAvailable responses
Extracts form field data from a fillable PDF document. You can either upload a new PDF file or provide the documentId of an existing file stored on the server. The endpoint returns all form fields and their corresponding values in JSON format.
Endpoint
Examples
const fs = require("fs/promises");
(async () => {
const form = new FormData();
const bytes = await fs.readFile("YOUR_FILE.pdf");
const file = new File([bytes], "YOUR_FILE.pdf", { type: "application/pdf" });
form.append("file", file);
const res = await fetch("https://api.pdfgate.com/forms/extract-data", {
method: "POST",
body: form,
headers: { Authorization: "Bearer YOUR_API_KEY" },
});
if (res.status === 201) {
const data = await res.json();
console.log(data);
} else {
const text = await res.text();
console.error(text);
}
})();
Request body fields
.pdfAvailable responses
Applies a watermark (either text or image) to a PDF document. The endpoint accepts one main PDF file or a reference to an existing document (via documentId) and optional parameters for watermark customization. It returns a new PDF file containing the applied watermark.
Endpoint
Examples
const fs = require("fs/promises");
(async () => {
const form = new FormData();
const bytes = await fs.readFile("YOUR_FILE.pdf");
const file = new File([bytes], "YOUR_FILE.pdf", { type: "application/pdf" });
form.append("file", file);
form.append('type', 'text');
form.append('text', "My watermark!")
form.append('rotate', "30")
form.append("font", "helvetica-boldoblique")
form.append("fontSize", "20")
form.append('fontColor', "rgba(156, 50, 168)")
form.append('opacity', '0.2')
const res = await fetch("https://api.pdfgate.com/watermark/pdf", {
method: "POST",
body: form,
headers: { Authorization: "Bearer YOUR_API_KEY" },
});
if (res.status === 201) {
const buf = Buffer.from(await res.arrayBuffer());
await fs.writeFile("watermarked.pdf", buf);
} else {
const text = await res.text();
console.error(text);
}
})();
Request body fields
.pdf.png .jpeg .jpg.ttf .otffontFile is provided, this parameter will be ignored.Available responses
Applies password protection and permission restrictions to a PDF file. This endpoint allows you to encrypt a PDF using AES-128 or AES-256 encryption, define user and owner passwords, and optionally disable printing, copying, and editing. You can also decide whether to encrypt the document's metadata.
The operation produces a new, protected PDF file without altering the original.
Endpoint
Examples
const fs = require("fs/promises");
(async () => {
const form = new FormData();
const bytes = await fs.readFile("YOUR_FILE.pdf");
const file = new File([bytes], "YOUR_FILE.pdf", { type: "application/pdf" });
form.append("file", file);
form.append("ownerPassword", "ownerPassword");
form.append("userPassword", "userPassword");
form.append("disablePrint", "true");
form.append("disableCopy", "true");
form.append("disableEditing", "true");
const res = await fetch("https://api.pdfgate.com/protect/pdf", {
method: "POST",
body: form,
headers: { Authorization: "Bearer YOUR_API_KEY" },
});
if (res.status === 201) {
const buf = Buffer.from(await res.arrayBuffer());
await fs.writeFile("protected.pdf", buf);
} else {
const text = await res.text();
console.error(text);
}
})();
Request body fields
.pdfAvailable responses
Optimizes a PDF to reduce file size without changing its visual content. The endpoint rewrites the file using modern, compact structures (object streams) and compresses stream data (Flate/deflate). You can also enable linearization (“Fast Web View”) so the first page renders sooner when the PDF is viewed over the network.
Endpoint
Examples
const fs = require("fs/promises");
(async () => {
const form = new FormData();
const bytes = await fs.readFile("YOUR_FILE.pdf");
const file = new File([bytes], "YOUR_FILE.pdf", { type: "application/pdf" });
form.append("file", file);
form.append("linearize", "true");
const res = await fetch("https://api.pdfgate.com/compress/pdf", {
method: "POST",
body: form,
headers: { Authorization: "Bearer YOUR_API_KEY" },
});
if (res.status === 201) {
const buf = Buffer.from(await res.arrayBuffer());
await fs.writeFile("compressed.pdf", buf);
} else {
const text = await res.text();
console.error(text);
}
})();
Request body fields
.pdfAvailable responses
Retrieves a generated document object containing metadata and file details.
Endpoint
Examples
const fetch = require("node-fetch");
const options = {
method: "GET",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
},
};
fetch("https://api.pdfgate.com/document/{documentId}", options).then( async (result) => {
const data = await result.json();
});Request query fields
Response
Retrieves a raw PDF file previously generated.
Note: To access a generated file, the “Save files for one month” option must be enabled in your Dashboard's settings. This option is disabled by default.
Endpoint
Examples
const fetch = require("node-fetch");
const fs = require("fs");
const options = {
method: "GET",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
},
};
fetch("https://api.pdfgate.com/file/{documentId}", options).then( async (result) => {
result.body.pipe(fs.createWriteStream("file_name.pdf"));
});Response