SDK Initialization

To interact with the API, you must initialize the ForkPDFClient with your API Key and Project ID. You can find both of these in your dashboard.

Verify Your Credentials

Use the List PDFs endpoint with limit=1 to confirm your API key and project ID before generating a document:

curl "https://api.forkpdf.com/v1/pdfs?limit=1" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-project-id: YOUR_PROJECT_ID"

Example Response

{
  "success": true,
  "data": [],
  "meta": {
    "totalItems": 0,
    "currentPage": 1,
    "itemsPerPage": 1,
    "totalPages": 0
  }
}

SDK

SDK 2.1.0 supports native ESM named imports and CommonJS require. Both formats expose the same classes and types.

const { ForkPDFClient } = require('forkpdf');

// Initialize the client
const client = new ForkPDFClient('pk_live_...', 'your-project-uuid');

Safe GET retries and backoff

The optional fourth constructor argument configures retries for idempotent GET requests. Transient network failures and 408, 429, and 5xx responses use exponential backoff. Generation POSTs are never retried automatically because they are not idempotent.

const client = new ForkPDFClient(apiKey, projectId, undefined, {
  retries: 2,        // additional GET attempts; default 2, clamped to 0–5
  retryDelayMs: 250  // base backoff delay; default 250, clamped to 0–5000
});

AbortSignal cancellation

Pass signal to generate() to cancel the generation request and any file download it performs. It is a local SDK option, not part of the API JSON payload. Cancellation throws ForkPDFError with code ABORT_ERROR.

const controller = new AbortController();
setTimeout(() => controller.abort(), 10_000);

try {
  const result = await client.generate({
    htmlContent: '<h1>Long render</h1>',
    format: 'A4',
    downloadBuffer: true,
    signal: controller.signal
  });
} catch (error) {
  if (error instanceof ForkPDFError && error.code === 'ABORT_ERROR') {
    // The caller cancelled the operation.
  }
}

Compliance capability discovery

SDK 2.1.0 adds the typed getComplianceCapabilities() method. PDF/UA-1 and PDF/UA-2 report stable; use the returned matrix to preflight supported PDF/A combinations and form capabilities.

const capabilities = await client.getComplianceCapabilities();
console.log(capabilities.pdfUa.status);     // 'stable'
console.log(capabilities.pdfUa.supported); // [1, 2]