Logologo-hidden
mobile-nav-icon

Overview

The PdfGate API provides simple HTTP endpoints to generate high quality PDF files based on an HTML document or a URL resource. In this page you will find everything you need in order to use the API.

Authentication

To use the API, you need to always authenticate the HTTP requests you initiate. PdfGate is using API keys for the authentication.

Firstly, you need to login to your account and create an API key. Make sure it is active and then you can use it in your source code.

In your HTTP requests you need to provide the Authorization header with the value Bearer YOUR_API_KEY.

There are two types of API keys. Production and Sandbox keys and they should have the following format.

  • Production: live_xxxxxxxxxxxxxxx
  • Sandbox: test_xxxxxxxxxxxxxxx

Rate limits

The PdfGate API is using different rate limits for each account type in Production environment for different endpoints. For Sandbox environment the rate limits are the same for all account types.

EndpointProductionSandbox
POST /generate/pdf
Per account type:
  • Starter: 5
  • Basic: 15
  • Professional: 20
  • Professional Plus: 50
Per account type:
  • Starter: Not Available
  • Basic: 2
  • Professional: 2
  • Professional Plus: 2
GET /get-document100 concurrent requests50 concurrent requests
GET /get-file100 concurrent requests50 concurrent requests

Generate PDF

In order to create a PDF document, you need to send a URL or HTML in the request body and in the headers you should include your API key and the content type.

With this endpoint you can have two response types. By default you will get a raw PDF file and by specifying the field jsonResponse you can get a JSON response with the details of your generated document.

Endpoint

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

Examples

NODE.JS
PYTHON
CURL
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/Cupcake",
        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.
pageSizeType enum
Default: ledger
Possible 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 enum
Default: portrait
Possible values
portraitlandscape
header string
footer string
margin object
timeout number
Default: 30000
Maximum wait time to render the HTML content in milliseconds.
security object
javascript string
css string
emulateMediaType enum
Sets the CSS media type of the document.
Possible 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.
httpHeaders object
Sets custom HTTP headers.
metadata object
Sets custom data to your document record.

Available responses

File stream
{"id" : "6642381c5c61""status" : "completed""fileUrl" : "https://api.pdfgate.com/get-file/6642381c5c61""documentUrl" : "https://api.pdfgate.com/get-document/6642381c5c61""contentSize" : 1620006"createdAt" : "2024-02-13T15:56:12.607Z"}

Get document

Gets a generated document object.

Endpoint

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

Examples

NODE.JS
PYTHON
CURL
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/get-document/{documentId}", options).then( async (result) => {
    const data = await result.json();
});

Response

{"id" : "6642381c5c61""status" : "completed""fileUrl" : "https://api.pdfgate.com/get-file/6642381c5c61""documentUrl" : "https://api.pdfgate.com/get-document/6642381c5c61""contentSize" : 1620006"createdAt" : "2024-02-13T15:56:12.607Z"}

Get file

Gets a raw PDF file.

Endpoint

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

Examples

NODE.JS
PYTHON
CURL
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/get-file/{documentId}", options).then( async (result) => {
    result.body.pipe(fs.createWriteStream("file_name.pdf"));
});

Response

File stream