Documentation Index
Fetch the complete documentation index at: https://docs.hookpdf.com/llms.txt
Use this file to discover all available pages before exploring further.
Client constructor
new HookPDF(apiKey, options?)
Create a new SDK client.
| Parameter | Type | Default | Description |
|---|
apiKey | string | - | Your HookPDF API key |
options.baseUrl | string | https://api.hookpdf.com | Base URL for API requests |
options.timeout | number | 30000 | Request timeout in milliseconds |
const HookPDF = require('hookpdf');
const client = new HookPDF('hp_live_your_api_key', {
baseUrl: 'https://api.hookpdf.com',
timeout: 30000
});
Methods
client.render(params)
Queue a production PDF render job.
const job = await client.render({
templateId: 'uuid-here',
payload: { name: 'John', date: '2026-03-05' },
options: {
pageSize: 'A4',
orientation: 'portrait',
locale: 'en-US'
}
});
// { jobId, status, isPreview }
client.renderPreview(params)
Queue a preview render job. The generated PDF is watermarked and short-lived.
const preview = await client.renderPreview({
templateId: 'uuid-here',
payload: { name: 'Test' }
});
client.getReport(jobId)
Get the current status for a render job.
const report = await client.getReport('job-uuid');
// {
// id,
// templateId,
// status,
// outputUrl,
// errorCode,
// errorMessage,
// isPreview,
// createdAt,
// completedAt
// }
client.waitForReport(jobId, options?)
Poll the API until the job completes or fails.
| Parameter | Type | Default | Description |
|---|
options.interval | number | 2000 | Polling interval in milliseconds |
options.timeout | number | 120000 | Maximum wait time in milliseconds |
const report = await client.waitForReport(job.jobId, {
interval: 3000,
timeout: 60000
});
if (report.outputUrl) {
console.log('Download:', report.outputUrl);
}
Error handling
SDK methods throw HookPDFError for API and transport failures.
const { HookPDFError } = require('hookpdf');
try {
await client.render({ templateId: 'bad-id', payload: {} });
} catch (err) {
if (err instanceof HookPDFError) {
console.error(err.message);
console.error(err.status);
console.error(err.errorCode);
console.error(err.requestId);
}
}
TypeScript
TypeScript definitions are bundled with the package.
import HookPDF, { Report, HookPDFError } from 'hookpdf';
const client = new HookPDF('hp_live_xxx');
try {
const report: Report = await client.waitForReport('job-id');
console.log(report.outputUrl);
} catch (err) {
if (err instanceof HookPDFError) {
console.error(err.errorCode);
}
}