API Documentation

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.

Authentication

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_KEY

PDFGate supports two types of API keys:

  • Production: live_xxxxxxxxxxxxxxx
  • Sandbox: test_xxxxxxxxxxxxxxx

Use sandbox keys for testing purposes and production keys in your live environment.

Rate limits

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.

EndpointProductionSandbox
POST /v1/generate/pdf
POST /forms/flatten
POST /forms/extract-data
POST /watermark/pdf
POST /protect/pdf
POST /compress/pdf
Per account type:
  • Starter: 3
  • Basic: 5
  • Professional: 10
  • Professional Plus: 20
Per account type:
  • Starter: Not Available
  • Basic: 2
  • Professional: 2
  • Professional Plus: 2
GET /document
40 concurrent requests10 concurrent requests
GET /file
40 concurrent requests10 concurrent requests

Errors

CodeError
400Bad request
401Unauthorized
404Not found
422Unprocessable entity
429Too many requests
500Internal server error

Generate PDF

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

POSThttps://api.pdfgate.com/v1/generate/pdf

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
C#
RUBY
copy-integration-source-code-icon
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

html string required if url field is not provided
url string required if html field is not provided
jsonResponse boolean
Default: false
Returns JSON response instead of file stream.
preSignedUrlExpiresIn number
Minimum: 60 seconds
Maximum: 86400 seconds (24 hours)
Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.
If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.
pageSizeType string
Default: ledger
Acceptable values
a0a1a2a3a4a5a6ledgertabloidlegalletter
width number
Custom PDF file width in pixels (px). It needs to be defined with the height field.
height number
Custom PDF file height in pixels (px). It needs to be defined with the width field.
orientation string
Default: portrait
Acceptable values
portraitlandscape
header string
footer string
margin object
timeout number
Default: 900000 - (15 minutes)
Maximum wait time (in milliseconds) to render the HTML content. The default and maximum value is 900000 ms (15 minutes) and cannot be increased. Use this parameter to stop the rendering process earlier if needed.
javascript string
css string
emulateMediaType string
Sets the CSS media type of the document.
Acceptable values
screenprint
waitForSelector string
Waits for specific CSS selector to be loaded. It will timeout in 30 seconds.
clickSelector string
Waits and then clicks a specific CSS selector.
waitForNetworkIdle boolean
Waits until there are no more network connections in the document.
delay number
Adds a delay in milliseconds before processing the HTML content into a PDF. This can be useful when asynchronous content needs extra time to render. The maximum value you can set is 20 seconds (20000 in ms).
loadImages boolean
Waits for all images to finish loading before generating the PDF.
scale number
Default: 1
Sets the page scale factor when generating the PDF. Accepts values between 0.1 and 2.
pageRanges string
Defines the page range to include in the PDF. Accepts formats like "1-5" or "1,3,5". If not specified, all pages are included.
printBackground boolean
Default: true
Includes background graphics in the PDF when set to true. If false, backgrounds are omitted and only main content is rendered.
httpHeaders object
Sets custom HTTP headers.
enableFormFields boolean
If enabled, the generated PDF will include interactive form fields (e.g., text inputs, checkboxes) that users can fill out directly in PDF viewers.
Supported HTML tags
input[type='text'] input[type='checkbox'] textarea select input[type='email'] input[type='number'] input[type='datetime-local'] input[type='date'] input[type='time'] input[type='radio']
For digital signature field we support the following custom HTML tag
<pdfgate-signature-field />
metadata object
Sets custom data to your document record.

Available responses

File stream
{"id" : "6642381c5c61""status" : "completed""type" : "from_html","fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken""size" : 1620006"createdAt" : "2024-02-13T15:56:12.607Z"}

Flatten PDF

The Flatten PDF endpoint converts an interactive PDF (with fillable form fields or annotations) into a static, non-editable version.

You can flatten a document in two ways:
  • Upload a PDF file with form data directly, or
  • Provide a 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

POSThttps://api.pdfgate.com/forms/flatten

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
RUBY
copy-integration-source-code-icon
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

file file required if documentId is not provided
File type: .pdf
The PDF file to be processed. Used when uploading a new file directly.
documentId string required if uploaded file is not provided
The ID of an already uploaded file stored on our server.
jsonResponse boolean
Default: false
Returns JSON response instead of file stream.
preSignedUrlExpiresIn number
Minimum: 60 seconds
Maximum: 86400 seconds (24 hours)
Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.
If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.
metadata object
Sets custom data to your document record.

Available responses

File stream
{"id" : "6642381c5c61","status" : "completed","fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken""size" : 1620006,"type" : "flattened","derivedFrom" : "68f920bacfe16de217f019as","createdAt" : "2024-02-13T15:56:12.607Z"}

Extract PDF Form Data

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

POSThttps://api.pdfgate.com/forms/extract-data

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
RUBY
copy-integration-source-code-icon
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

file file required if documentId is not provided
File type: .pdf
The PDF file to be processed. Used when uploading a new file directly.
documentId string required if uploaded file is not provided
The ID of an already uploaded file stored on our server.

Available responses

{...pdf_form_data_in_json,}

Watermark PDF

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

POSThttps://api.pdfgate.com/watermark/pdf

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
RUBY
copy-integration-source-code-icon
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

file file required if documentId is not provided
File type: .pdf
The source PDF file to watermark. Either file or documentId must be provided.
documentId string required if uploaded file is not provided
The unique identifier of an existing uploaded document. Use this when watermarking a file that's already stored on our database.
watermark file
File types: .png .jpeg .jpg
The image to be used as a watermark. Provide this field if you want an image watermark instead of text.
fontFile file
File types: .ttf .otf
A custom font file for text watermarks.
type string required
Acceptable values
textimage
Use text for a text watermark and image for an image watermark.
text string required if type is set to text
The text you want to appear as the watermark.
font string
Default: helvetica
Acceptable values
times-romantimes-boldtimes-italictimes-bolditalichelveticahelvetica-boldhelvetica-obliquehelvetica-boldobliquecouriercourier-boldcourier-obliquecourier-boldoblique
The font name to use for the text watermark. Must be one of the standard PDF fonts. If the fontFile is provided, this parameter will be ignored.
fontSize number
Default: 30
The size of the watermark text, in points.
fontColor string
The color of the text watermark. Accepts a hex color (e.g., #FF0000) or an RGB value (e.g., rgb(255,0,0)).
opacity number
Default: 1
Sets the transparency of the watermark, from 0 (fully transparent) to 1 (fully opaque). It applies to both text and image watermarks.
xPosition number
The horizontal position (in points) where the image or text watermark will be placed. If not provided a centered position will be applied.
yPosition number
The vertical position (in points) where the image or text watermark will be placed. If not provided, a centered position will be applied.
imageWidth number
The width (in points) to resize the watermark image to. If not provided, the image keeps its original width.
imageHeight number
The height (in points) to resize the watermark image to. If not provided, the image keeps its original height.
rotate number
Rotates the watermark by the specified angle in degrees (0-360). Useful for diagonal watermarks.
jsonResponse boolean
Default: false
Returns JSON response instead of file stream.
preSignedUrlExpiresIn number
Minimum: 60 seconds
Maximum: 86400 seconds (24 hours)
Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.
If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.
metadata object
Sets custom data to your document record.

Available responses

File stream
{"id" : "6642381c5c61","status" : "completed","fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken""size" : 1620006,"type" : "watermarked","derivedFrom" : "68f920bacfe16de217f019as","createdAt" : "2024-02-13T15:56:12.607Z"}

Protect PDF

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

POSThttps://api.pdfgate.com/protect/pdf

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
RUBY
copy-integration-source-code-icon
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

file file required if documentId is not provided
File type: .pdf
The PDF file to be processed. Used when uploading a new file directly.
documentId string required if uploaded file is not provided
The ID of an already uploaded file stored on our server.
algorithm string
Default: AES256
Acceptable values
AES256AES128
Specifies the encryption algorithm. AES256 offers the highest security, while AES128 ensures better compatibility with older PDF readers.
userPassword string
Password required to open the PDF. If not provided, the document will be accessible without a password unless restrictions depend on the owner password.
ownerPassword string
Password that grants full control over the PDF, including the ability to change permissions or remove restrictions. Must not be empty if AES256 is used and a userPassword is defined.
disablePrint boolean
When true, prevents the PDF from being printed.
disableCopy boolean
When true, disables copying or text/image extraction from the document.
disableEditing boolean
When true, prevents modifications to the document (e.g., form editing or annotation changes).
encryptMetadata boolean
Default: false
Determines whether the document metadata (title, author, keywords, etc.) should be encrypted. If set to false, metadata remains visible without decryption.
jsonResponse boolean
Default: false
Returns JSON response instead of file stream.
preSignedUrlExpiresIn number
Minimum: 60 seconds
Maximum: 86400 seconds (24 hours)
Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.
If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.
metadata object
Sets custom data to your document record.

Available responses

File stream
{"id" : "6642381c5c61","status" : "completed","fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken""size" : 1620006,"type" : "encrypted","derivedFrom" : "68f920bacfe16de217f019as","createdAt" : "2024-02-13T15:56:12.607Z"}

Compress PDF

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

POSThttps://api.pdfgate.com/compress/pdf

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
RUBY
copy-integration-source-code-icon
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

file file required if documentId is not provided
File type: .pdf
The PDF file to be processed. Used when uploading a new file directly.
documentId string required if uploaded file is not provided
The ID of an already uploaded file stored on our server.
linearize boolean
Default: false
When true, rearranges the PDF for Fast Web View so the first page can render before the full file downloads.
jsonResponse boolean
Default: false
Returns JSON response instead of file stream.
preSignedUrlExpiresIn number
Minimum: 60 seconds
Maximum: 86400 seconds (24 hours)
Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.
If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.
metadata object
Sets custom data to your document record.

Available responses

File stream
{"id" : "6642381c5c61","status" : "completed","fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken""size" : 1620006,"type" : "compressed","derivedFrom" : "68f920bacfe16de217f019as","createdAt" : "2024-02-13T15:56:12.607Z"}

Get document

Retrieves a generated document object containing metadata and file details.

Endpoint

GEThttps://api.pdfgate.com/document/{documentId}

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
C#
RUBY
copy-integration-source-code-icon
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

preSignedUrlExpiresIn number
Minimum: 60 seconds
Maximum: 86400 seconds (24 hours)
Use this to receive a temporary authorized URL for an existing file. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.

Response

{"id" : "6642381c5c61""status" : "completed""fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken""size" : 1620006"createdAt" : "2024-02-13T15:56:12.607Z"}

Get file

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

GEThttps://api.pdfgate.com/file/{documentId}

Examples

NODE.JS
PYTHON
GO
CURL
PHP
JAVA
C#
RUBY
copy-integration-source-code-icon
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

File stream