Compress/optimize a PDF to reduce file size.
Endpoint: POST /compress/pdf
Provide either:
file (upload a PDF), ordocumentId (reference an existing stored document).Compression optimizes internal structures and stream compression without changing visual content.
Optionally enable linearize to help the first page render sooner over the network.
By default returns a raw PDF stream (handled here as Buffer).
If jsonResponse: true, returns a JSON document object (PdfGateDocument) with metadata and fileUrl.
preSignedUrlExpiresIn is in seconds (min 60, max 86400).
Compress options; includes file or documentId, optional linearize, jsonResponse, metadata, etc.
A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.
Extract form field data from a fillable PDF and return it as JSON.
Endpoint: POST /forms/extract-data
Provide either:
file (upload a PDF), ordocumentId (reference an existing stored document).The response is a JSON object mapping form field names to their values.
Extraction request; includes file or documentId.
A plain JSON object containing extracted PDF form data.
Flatten an interactive PDF into a static, non-editable PDF.
Endpoint: POST /forms/flatten
Provide either:
file (upload a PDF), ordocumentId (reference an existing stored document).If documentId is provided, PDFGate creates a new flattened document (does not overwrite).
When jsonResponse: true, the response may include derivedFrom to indicate the original document ID.
By default returns a raw PDF stream (handled here as Buffer).
If jsonResponse: true, returns a JSON document object (PdfGateDocument) with metadata and fileUrl.
preSignedUrlExpiresIn is in seconds (min 60, max 86400).
Flatten options; includes file or documentId, optional jsonResponse, metadata, etc.
A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.
Generate a PDF from a URL or raw HTML.
Endpoint: POST /v1/generate/pdf
You must provide either:
url (render a public page), orhtml (render raw HTML).By default the API returns a raw PDF stream (handled here as a Buffer).
If jsonResponse: true, the API returns a document JSON object with metadata,
including a temporary fileUrl (pre-signed URL) when enabled.
Notes from the API docs:
preSignedUrlExpiresIn is in seconds (min 60, max 86400).timeout is in milliseconds, default/max 900000 (15 minutes).pageRanges, etc.enableFormFields enables interactive fields based on supported HTML tags
(and supports <pdfgate-signature-field />).Generation options; must include url or html.
A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.
Retrieve a stored document’s metadata (and optionally a fresh pre-signed download URL).
Endpoint: GET /document/{documentId}
Use this to fetch the document record (id, status, size, createdAt, etc.).
If you need a new pre-signed URL for downloading an existing stored file,
set preSignedUrlExpiresIn (seconds, min 60, max 86400).
The document ID.
Optional; pre-signed URL expiry in seconds.
The PdfGateDocument object.
Download a raw PDF file by document ID.
Endpoint: GET /file/{documentId}
Important: Accessing stored generated files requires enabling “Save files” in the PDFGate Dashboard settings (disabled by default).
The document ID to download.
The PDF bytes as a Buffer.
Protect a PDF using encryption + optional permission restrictions.
Endpoint: POST /protect/pdf
Provide either:
file (upload a PDF), ordocumentId (reference an existing stored document).Security options highlights:
algorithm: "AES256" (default) or "AES128".userPassword: password required to open the PDF (optional).ownerPassword: full control password; required in some cases (e.g., AES256 with userPassword).disablePrint, disableCopy, disableEditing.encryptMetadata: whether PDF metadata is encrypted (default false).The operation produces a new protected file and does not alter the original.
By default returns a raw PDF stream (handled here as Buffer).
If jsonResponse: true, returns a JSON document object (PdfGateDocument) with metadata and fileUrl.
preSignedUrlExpiresIn is in seconds (min 60, max 86400).
Protect options; includes file or documentId, encryption/restriction settings, etc.
A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.
Apply a text or image watermark to a PDF.
Endpoint: POST /watermark/pdf
Provide either:
file (upload a PDF), ordocumentId (reference an existing stored document).Watermark configuration highlights:
type is required: "text" or "image".text required when type="text".watermark image file (.png, .jpg, .jpeg).font (standard PDF fonts), fontFile (.ttf/.otf overrides font),
fontSize, fontColor, opacity (0..1), xPosition, yPosition, imageWidth, imageHeight, rotate (0..360).By default returns a raw PDF stream (handled here as Buffer).
If jsonResponse: true, returns a JSON document object (PdfGateDocument) with metadata and fileUrl.
preSignedUrlExpiresIn is in seconds (min 60, max 86400).
Watermark options; includes file or documentId plus watermark settings.
A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.
Create a new PDFGate client.
PDFGate uses two environments:
test_...keys →https://api-sandbox.pdfgate.comlive_...keys →https://api.pdfgate.comAuthentication is performed via the
Authorization: Bearer <API_KEY>header.