pdfgate
    Preparing search index...

    Class default

    Index

    Constructors

    • Create a new PDFGate client.

      PDFGate uses two environments:

      • Sandbox for test_... keys → https://api-sandbox.pdfgate.com
      • Production for live_... keys → https://api.pdfgate.com

      Authentication is performed via the Authorization: Bearer <API_KEY> header.

      Parameters

      • apiKey: string

        Your PDFGate API key (must start with test_ or live_).

      Returns default

      If the API key format is invalid.

    Methods

    • Compress/optimize a PDF to reduce file size.

      Endpoint: POST /compress/pdf

      Provide either:

      • file (upload a PDF), or
      • documentId (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).

      Type Parameters

      • P extends CompressPdfRequest

      Parameters

      • params: P

        Compress options; includes file or documentId, optional linearize, jsonResponse, metadata, etc.

      Returns Promise<CompressPdfResponse<P>>

      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), or
      • documentId (reference an existing stored document).

      The response is a JSON object mapping form field names to their values.

      Parameters

      • params: ExtractPdfDataRequest

        Extraction request; includes file or documentId.

      Returns Promise<Record<string, any>>

      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), or
      • documentId (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).

      Type Parameters

      • P extends FlattenPdfRequest

      Parameters

      • params: P

        Flatten options; includes file or documentId, optional jsonResponse, metadata, etc.

      Returns Promise<FlattenPdfResponse<P>>

      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), or
      • html (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).
      • Supports options like page size/orientation, margins, header/footer, JS/CSS injection, wait strategies, pageRanges, etc.
      • enableFormFields enables interactive fields based on supported HTML tags (and supports <pdfgate-signature-field />).

      Type Parameters

      • P extends GeneratePdfRequest

      Parameters

      • params: P

        Generation options; must include url or html.

      Returns Promise<GeneratePdfResponse<P>>

      A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.

      If neither url nor html is provided.

    • 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).

      Parameters

      • params: GetDocumentRequest
        • id

          The document ID.

        • preSignedUrlExpiresIn

          Optional; pre-signed URL expiry in seconds.

      Returns Promise<PdfGateDocument>

      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).

      Parameters

      • params: GetFileRequest
        • documentId

          The document ID to download.

      Returns Promise<Buffer<ArrayBufferLike>>

      The PDF bytes as a Buffer.

    • Protect a PDF using encryption + optional permission restrictions.

      Endpoint: POST /protect/pdf

      Provide either:

      • file (upload a PDF), or
      • documentId (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).
      • Restrictions: 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).

      Type Parameters

      • P extends ProtectPdfRequest

      Parameters

      • params: P

        Protect options; includes file or documentId, encryption/restriction settings, etc.

      Returns Promise<ProtectPdfResponse<P>>

      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), or
      • documentId (reference an existing stored document).

      Watermark configuration highlights:

      • type is required: "text" or "image".
      • For text watermarks: text required when type="text".
      • For image watermarks: upload watermark image file (.png, .jpg, .jpeg).
      • Optional: 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).

      Type Parameters

      • P extends WatermarkPdfRequest

      Parameters

      • params: P

        Watermark options; includes file or documentId plus watermark settings.

      Returns Promise<WatermarkPdfResponse<P>>

      A Buffer (PDF bytes) by default, or a PdfGateDocument when jsonResponse: true.