lmn1919/dompdf.js
소개
브라우저에서 HTML을 PDF로 변환합니다. 코드 한 줄로 텍스트를 선택하고 검색할 수 있는 벡터 PDF(10,000페이지 이상)를 생성합니다. 순수 프런트엔드로 백엔드와 런타임 의존성이 전혀 없습니다. Rust + WebAssembly 엔진을 기반으로 한 TypeScript 구현이며, html2canvas/jsPDF의 대안입니다.
웹 및 앱 개발What you can do
- 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.
측정된 스타 증가
- in 24h
- +1
- in 7 days
- +13
- in 15 days
- +20
- in 1 month
- +44
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originaldompdf.js
Pure-frontend DOM-to-PDF engine powered by TypeScript, Web Workers, Rust, and WebAssembly.
Documentation | Live Demo | 10k Pages Demo | PDF Editor | 中文文档
Real browser recording: exporting 10,000 A4 pages (17.5 MB, 7.7 s actual export time, accelerated playback) in a Web Worker + Rust/WASM, then selecting real vector text on page 7,342.
Note: This benchmark uses a plain vector-text ledger (no heavy images/rasterization or CJK font subsetting); real-world complex pages will take longer depending on DOM depth, wrapped text, images, and embedded fonts.
Features
- 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.
Installation
npm
npm install dompdf.js
CDN
<script src="https://cdn.jsdelivr.net/npm/dompdf.js@latest/dist/dompdf.min.js"></script>
Quick Start
Generate and Preview PDF Blob
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);
Documentation
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
Examples & Demos
- 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.
Contributing
Please read CONTRIBUTING.md before submitting a PR, and run at least:
npm test
npm run build
Security
Please report security issues according to SECURITY.md. Do not disclose unpatched vulnerabilities in public issues.
Changelog
See CHANGELOG.md for recent version changes.
License
This project is open-sourced under the MIT License.
관련 프로젝트 살펴보기
불러오는 중…