TypeScript SDK
@pdfend/sdk is a tiny, dependency-free client with typed inputs and results. Works in Node 18+, Bun, and anywherefetch is available.
Install
bashexample
npm install @pdfend/sdkCreate a client
typescriptexample
import { PDFend } from "@pdfend/sdk";
const pdfend = new PDFend(process.env.PDFEND_API_KEY!);Generate
typescriptexample
const { url, pages } = await pdfend.generate({
html: "<h1>Invoice</h1>",
options: {
format: "A4",
margin: { top: "20mm", bottom: "20mm" },
printBackground: true,
},
});Templates
typescriptexample
await pdfend.createTemplate({
name: "invoice-v1",
html: "<h1>Invoice {{number}}</h1>",
});
await pdfend.generate({
template: "invoice-v1",
data: { number: 1042 },
});Error handling
typescriptexample
import { PDFendError } from "@pdfend/sdk";
try {
await pdfend.generate({ html: "<h1>Hi</h1>" });
} catch (err) {
if (err instanceof PDFendError) {
console.error(err.code, err.statusCode, err.requestId);
}
}Custom base URL
Point the SDK at a self-hosted instance or staging:
typescriptexample
const pdfend = new PDFend({
apiKey: "pk_live_...",
baseUrl: "https://pdf.internal.example.com",
});