Pure-frontend DOM-to-PDF engine powered by TypeScript, Web Workers, Rust, and WebAssembly.
Documentation | Live Demo | PDF Editor | 中文文档
- Pure Frontend Zero Dependencies: No document uploads or backend servers required. All DOM geometry extraction and PDF compilation are completed locally in the browser.
- High-Definition Vector Typesetting: Produces searchable, selectable, and copyable high-fidelity vector text and paths, avoiding low-quality full-page screenshots.
- High-Performance Architecture: Compiled on background worker threads via WebAssembly and Web Workers—a 500-page long document exports in ~2 seconds.
- Full-Featured: Supports smart multi-page pagination, Chinese and custom TTF fonts (with built-in subset compression), text/image watermarks, dynamic headers and footers, SVG/Canvas/CSS styling, hyperlinks, interactive forms (AcroForm), and PDF security encryption.
npm install dompdf.js<script src="https://cdn.jsdelivr.net/npm/dompdf.js@latest/dist/dompdf.min.js"></script>import dompdf from "dompdf.js";
const element = document.querySelector("#content");
const blob = await dompdf(element, {
format: "a4",
pagination: true,
backgroundColor: "#ffffff",
});
const url = URL.createObjectURL(blob);
window.open(url, "_blank");
setTimeout(() => URL.revokeObjectURL(url), 30_000);Comprehensive bilingual interactive documentation and detailed API references have been migrated to the standalone docs page:
- Online Documentation: https://dompdfjs.lisky.com.cn/docs.html
Covered topics:
- Full export configuration options and API reference
- Page sizes, margins, custom dimensions, and advanced pagination controls
- Header and footer templates with dynamic page-number placeholders
- Text and image watermarks (opacity, layering, rotation, and per-page control)
- Unicode multilingual support, custom TTF font loading, and font subsetting
- Interactive forms (AcroForm) and static form exports
- PDF encryption (user/owner passwords, permissions)
- SVG, Canvas, advanced CSS effects, and cross-origin images
- Export progress callbacks and low-level Snapshot APIs
- dompdf.js Studio: Live HTML/CSS editing and real-time dual-pane PDF preview workbench.
- Documentation Center: Comprehensive bilingual API manual and code examples.
- PDF Editor: Online PDF editor powered by dompdf.js.
Please read CONTRIBUTING.md before submitting a PR, and run at least:
npm test
npm run buildPlease report security issues according to SECURITY.md. Do not disclose unpatched vulnerabilities in public issues.
See CHANGELOG.md for recent version changes.
This project is open-sourced under the MIT License.
