# DocFast Node.js SDK Official Node.js client for the [DocFast](https://docfast.dev) HTML-to-PDF API. ## Install ```bash npm install docfast ``` Requires Node.js 18+ (uses native `fetch`). Zero runtime dependencies. ## Quick Start ```typescript import DocFast from 'docfast'; const client = new DocFast('df_pro_your_api_key'); // HTML to PDF const pdf = await client.html('

Hello World

'); 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`. ### `client.markdown(markdown, options?)` Convert a Markdown string to PDF. Returns `Promise`. ### `client.url(url, options?)` Convert a webpage URL to PDF. Returns `Promise`. ### `client.templates()` List available templates. Returns `Promise`. ### `client.renderTemplate(id, data, options?)` Render a template with data. Returns `Promise`. ### PDF Options All conversion methods accept an optional `options` object: ```typescript { format: 'A4' | 'Letter' | 'Legal' | 'A3' | 'A5' | 'Tabloid', landscape: boolean, margin: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' }, header: { content: '
Header HTML
', height: '30mm' }, footer: { content: '
Footer HTML
', height: '20mm' }, scale: 1.0, printBackground: true, } ``` ## Error Handling ```typescript import DocFast, { DocFastError } from 'docfast'; try { const pdf = await client.html('

Test

'); } catch (err) { if (err instanceof DocFastError) { console.error(err.message); // "Invalid API key" console.error(err.status); // 403 } } ``` ## License MIT