|
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Node.js SDK (sdk/nodejs/): TypeScript, zero deps, native fetch, Node 18+ - Python SDK (sdk/python/): sync + async clients via httpx, Python 3.8+ - Both wrap all conversion endpoints (html, markdown, url, templates) - Proper error handling with DocFastError - Full README documentation for each |
||
|---|---|---|
| .. | ||
| src | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
DocFast Node.js SDK
Official Node.js client for the DocFast HTML-to-PDF API.
Install
npm install docfast
Requires Node.js 18+ (uses native fetch). Zero runtime dependencies.
Quick Start
import DocFast from 'docfast';
const client = new DocFast('df_pro_your_api_key');
// HTML to PDF
const pdf = await client.html('<h1>Hello World</h1>');
fs.writeFileSync('output.pdf', pdf);
// Markdown to PDF
const pdf2 = await client.markdown('# Hello\n\nThis is **bold**.');
fs.writeFileSync('doc.pdf', pdf2);
// URL to PDF
const pdf3 = await client.url('https://example.com');
fs.writeFileSync('page.pdf', pdf3);
API
new DocFast(apiKey, options?)
| Parameter | Type | Description |
|---|---|---|
apiKey |
string |
Your DocFast API key |
options.baseUrl |
string |
API base URL (default: https://docfast.dev) |
client.html(html, options?)
Convert an HTML string to PDF. Returns Promise<Buffer>.
client.markdown(markdown, options?)
Convert a Markdown string to PDF. Returns Promise<Buffer>.
client.url(url, options?)
Convert a webpage URL to PDF. Returns Promise<Buffer>.
client.templates()
List available templates. Returns Promise<Template[]>.
client.renderTemplate(id, data, options?)
Render a template with data. Returns Promise<Buffer>.
PDF Options
All conversion methods accept an optional options object:
{
format: 'A4' | 'Letter' | 'Legal' | 'A3' | 'A5' | 'Tabloid',
landscape: boolean,
margin: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' },
header: { content: '<div>Header HTML</div>', height: '30mm' },
footer: { content: '<div>Footer HTML</div>', height: '20mm' },
scale: 1.0,
printBackground: true,
}
Error Handling
import DocFast, { DocFastError } from 'docfast';
try {
const pdf = await client.html('<h1>Test</h1>');
} catch (err) {
if (err instanceof DocFastError) {
console.error(err.message); // "Invalid API key"
console.error(err.status); // 403
}
}
License
MIT