How to Sign PDFs with TypeScript
To sign a PDF with TypeScript: Install the TurboDocx SDK (npm install @turbodocx/sdk), configure your API key with a typed HttpClientConfig, and call TurboSign.sendSignature() with a typed request.
The SDK is TypeScript-first: type definitions ship in the package, so requests and responses are typed end to end with no @types install.
5 min
Setup time
0 @types
Types ship with SDK
ESM + CJS
NodeNext ready
Installation and tsconfig
Install the TurboDocx SDK from npm. The package bundles its own .d.ts type definitions, so there is nothing extra to add for full type checking.
npm install @turbodocx/sdkFor modern ESM projects, use NodeNext module resolution and enable esModuleInterop. This lets you use import syntax in both Node and bundled apps.
{
"compilerOptions": {
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"target": "ES2022"
}
}Requirements: Node.js 18+ and TypeScript 4.7+. No @types/turbodocx package is needed; the types ship inside @turbodocx/sdk.
Obtaining an API Key
Before you begin, you'll need your API credentials from the TurboDocx dashboard.
- Sign up for a free account at TurboDocx
- Navigate to Settings → API Keys
- Copy your API Key and Organization ID
TURBODOCX_API_KEY=your_api_key_here
TURBODOCX_ORG_ID=your_org_id_here
TURBODOCX_SENDER_EMAIL=you@company.com
TURBODOCX_SENDER_NAME=Your Company NameSending a Signing Request
Import the SDK types alongside TurboSign so your configuration, recipients, and fields are checked at compile time. The recipient receives an email with a link to sign.
import { TurboSign, type HttpClientConfig, type Recipient, type Field, type SendSignatureResponse } from '@turbodocx/sdk';
import { readFileSync } from 'fs';
// Typed config. process.env values are string | undefined,
// which HttpClientConfig accepts.
const config: HttpClientConfig = {
apiKey: process.env.TURBODOCX_API_KEY,
orgId: process.env.TURBODOCX_ORG_ID,
senderEmail: process.env.TURBODOCX_SENDER_EMAIL, // REQUIRED
senderName: process.env.TURBODOCX_SENDER_NAME, // Recommended
};
TurboSign.configure(config);
// Read PDF file
const pdfBuffer: Buffer = readFileSync('contract.pdf');
// Typed recipients and fields
const recipients: Recipient[] = [
{ name: 'John Doe', email: 'john@example.com', signingOrder: 1 },
];
const fields: Field[] = [
{
type: 'signature',
recipientEmail: 'john@example.com',
template: {
anchor: '{signature1}',
placement: 'replace',
size: { width: 100, height: 30 },
},
},
];
// Send document for signature (fully typed response)
const result: SendSignatureResponse = await TurboSign.sendSignature({
file: pdfBuffer,
documentName: 'Partnership Agreement',
recipients,
fields,
});
console.log('Document ID:', result.documentId);Type safety: Because Recipient and Field are imported types, a missing signingOrder or an invalid field type fails to compile instead of failing at runtime. The senderEmail remains required and is used as the reply-to address.
Processing Results with Webhooks
Configure webhooks to receive real-time notifications when documents are signed. Typed Express handlers keep your request and response objects checked.
import express, { type Request, type Response } from 'express';
const app = express();
app.use(express.json());
app.post('/webhooks/turbosign', async (req: Request, res: Response) => {
const { event_type, data } = req.body;
if (event_type === 'document.completed') {
console.log('Document signed:', data.documentId);
// Download the signed PDF
const signedPdf = await TurboSign.download(data.documentId);
// Save to your storage
await saveToStorage(signedPdf, `signed-${data.documentId}.pdf`);
}
res.status(200).json({ received: true });
});Conclusion
You now have everything you need to integrate type-safe document signing into your TypeScript application. The TurboDocx SDK handles authentication, document delivery, signature collection, and provides legally-binding audit trails, all with types that ship in the package.
What you can do next:
- Add multiple recipients with sequential signing order
- Use different field types: initials, dates, text, checkboxes
- Embed signing directly in your app with iframe integration
- Get audit trails and compliance certificates
Related Guides
Resources
Frequently Asked Questions
How do I sign a PDF with TypeScript?
To sign a PDF with TypeScript, install the TurboDocx SDK (npm install @turbodocx/sdk), configure it with your typed API credentials, then call TurboSign.sendSignature() with a typed request. The SDK ships its own type definitions, so the request and response are fully typed.
Do I need a separate @types package for the TurboDocx SDK?
No. The TurboDocx SDK ships its own TypeScript definitions, so types for TurboSign.configure(), sendSignature(), Recipient, and Field work out of the box with no extra @types install.
Does the TurboDocx SDK work with ESM and NodeNext?
Yes. The SDK supports modern ESM and CommonJS. With "module": "NodeNext" and "esModuleInterop": true in your tsconfig, you can use import { TurboSign } from "@turbodocx/sdk" in both Node and bundled applications.
Ready to Get Started?
Create a free account and get your API key. Start sending documents for signature in minutes.