# Html2Pdf - Full Technical Documentation & LLM Guide > High-performance developer API and TypeScript SDK for converting HTML and CSS to pixel-perfect PDF documents with native Indian language typography. Html2Pdf provides a headless Chromium rendering pipeline built on Fastify, designed for mission-critical document generation (invoices, legal agreements, executive reports, tax filings). It bundles OpenType font rasterizers for 21 Indian languages across 12 scripts, validates all network sub-resources via a strict SSRF-filtering proxy, stores PDFs in S3-compatible cloud storage, and issues expiring presigned download URLs. --- ## 1. Quick Start ### Installation ```bash npm install @akcraft/html2pdf-sdk ``` ### Basic TypeScript Example ```typescript import { Html2PdfClient, PaperFormat, PdfOrientation } from '@akcraft/html2pdf-sdk'; // Initialize with your API key from https://html2pdf.akcraft.app/dashboard const client = new Html2PdfClient('your_api_key_here'); async function generateInvoice() { const response = await client.sendHtmlRequest({ userId: 'your_user_id_uuid', // Shown in dashboard Settings content: `
Billed to: Acme Corp
Total: $1,250.00
`, options: { format: PaperFormat.A4, orientation: PdfOrientation.PORTRAIT, printBackground: true, margin: { top: '15mm', bottom: '15mm', left: '12mm', right: '12mm', }, }, }); console.log('PDF generated successfully!'); console.log('Job ID:', response.jobId); console.log('Download URL:', response.pdfUrl); console.log('File Name:', response.fileName); } generateInvoice().catch(console.error); ``` --- ## 2. Architecture & Security 1. **Authentication & Authorization**: - API keys are created in the authenticated web dashboard (`/dashboard`). - Keys are stored exclusively as one-way SHA-256 hashes (`api_key_info` table). Raw keys are shown only once upon creation. - Keys are transmitted via the `x-api-key` HTTP header. - Every request verifies that the `x-api-key` is active (`revoked_at IS NULL`) and matches the `userId` in the payload. 2. **Isolated Headless Chromium Engine**: - Renders in-memory buffers using headless Chromium (Puppeteer). - Tini process reaper prevents zombie processes (`PID 1`). - Runs with `--no-sandbox --disable-setuid-sandbox` inside a non-root Linux container (`uid 997`). 3. **SSRF & Private Network Firewall**: - Chromium routes all network traffic through a local validating proxy (`--proxy-server`). - All requests to private IPv4 ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `127.0.0.0/8`, `169.254.0.0/16`) and local IPv6 literals are immediately aborted. - Local filesystem access (`file://`) is blocked. 4. **Storage & Lifecycle**: - Rendered PDFs are saved to S3-compatible cloud storage. - Presigned download URLs are generated with a 1-hour expiration time. - Automated cron workers delete PDFs older than the retention window (`PDF_RETENTION_HOURS`). Users can also delete PDFs on-demand. --- ## 3. TypeScript SDK Reference (`@akcraft/html2pdf-sdk`) ### `Html2PdfClient` Class #### Constructor ```typescript new Html2PdfClient(apiKey?: string) ``` - `apiKey` (optional): Default API key included in the `x-api-key` header on all requests. #### Methods ##### `sendHtmlRequest(request: SendHTMLRequest): PromiseGenerated via Html2Pdf API
", "options": { "format": "Letter", "orientation": "portrait", "printBackground": true } }' ``` --- ## 6. Indian Language Typography Support Html2Pdf solves the non-Latin conjunct rendering problem ("tofu" boxes `□□□`) by pre-bundling official Noto OpenType fonts directly inside the rendering runtime: | Script | Languages Supported | Bundled Noto Font | |---|---|---| | **Devanagari** | Hindi, Marathi, Sanskrit, Nepali, Konkani, Maithili, Bodo, Dogri | `Noto Sans Devanagari` | | **Bengali** | Bengali, Assamese, Bishnupriya | `Noto Sans Bengali` | | **Tamil** | Tamil | `Noto Sans Tamil` | | **Telugu** | Telugu | `Noto Sans Telugu` | | **Gujarati** | Gujarati | `Noto Sans Gujarati` | | **Gurmukhi** | Punjabi | `Noto Sans Gurmukhi` | | **Kannada** | Kannada | `Noto Sans Kannada` | | **Malayalam** | Malayalam | `Noto Sans Malayalam` | | **Odia** | Odia (Oriya) | `Noto Sans Oriya` | | **Nastaliq** | Urdu, Kashmiri, Sindhi | `Noto Nastaliq Urdu` | | **Ol Chiki** | Santali | `Noto Sans Ol Chiki` | | **Meetei Mayek** | Manipuri | `Noto Sans Meetei Mayek` | No extra font loading, link tags, or CSS imports are required in your HTML payloads for these languages; the fontconfig engine automatically applies the appropriate Noto typeface. --- ## 7. Dynamic Headers and Footers When `headerTemplate` or `footerTemplate` are provided, Chromium's print subsystem automatically injects document metadata into the following HTML class names: - ``: Formatted print date - ``: Document title - ``: Document location - ``: Current page number (1-based) - ``: Total page count *Tip*: Ensure your templates include `font-size` (minimum 8px) in inline styles; Chromium's default font size for headers and footers is 0px.