Skip to content
FossShelf
Home / Categories / For Web Developers

dompdf.js

Client-side HTML-to-PDF with vector text and no backend

Replaces Pdfshift, Docraptor, Api2pdf, Doppio

1.81K starsMITlast commit 12 Oct 2026

Who it's for

Frontend developers building invoice and receipt generators

Teams generating invoices or receipts from HTML templates can call downloadPDF on the rendered DOM element and trigger a browser download with no server round-trip. The MIT license and npm install fit cleanly into any frontend build pipeline.

Skip if invoices are generated server-side in a backend pipeline or need to be attached to emails without a browser present. dompdf.js requires a live DOM to operate.

SaaS teams exporting reports and design documentation

Apps that render structured reports, design specs, or data dashboards can export the current view to a paginated PDF with headers, footers, and page numbers. The client-side approach keeps report content within the user's browser session with no server logging.

Skip if reports are assembled server-side before delivery, or if the content pipeline runs in a Node.js environment without a browser.

Teams with document content privacy requirements

Because no document content is uploaded to a third-party server, dompdf.js suits applications handling confidential documents where routing content through a managed API service is not acceptable. Financial data, patient records, and NDA documents stay within the user's device.

Skip if your compliance model requires that documents only be generated in a controlled server environment and never rendered in an end-user browser.

The problem

Server-side PDF generation services charge per page or per API request and require sending document content to a third-party server. For teams generating invoices, design specs, or reports from HTML, this means recurring API costs, latency from a remote rendering step, and a decision about where document contents travel. Most browser-native PDF approaches reach for screenshot-based pipelines that rasterize the page into a full-page image and embed it in a PDF container. The result looks like a photograph rather than a document, with text that cannot be selected, copied, or searched. That breaks accessibility, breaks copy-paste workflows, and makes the output useless for any downstream tool that expects real text objects.

How it works

Vector PDF output with selectable text

Converts DOM elements to real PDF vector objects rather than rasterizing the page as a screenshot. Text in the exported file is selectable, searchable, and copyable, which is a requirement for invoices, legal documents, and any PDF intended for downstream text processing or accessibility tools.

Fully client-side rendering with no document upload

The entire render pipeline runs in the user's browser via Web Workers and WebAssembly. Document content never leaves the client, which removes the privacy trade-off required by server-side API services. Web Workers keep main-thread rendering non-blocking during export.

Paginated documents with headers, footers, and watermarks

Supports standard paginated output across A/B/C series, Letter, Legal, Tabloid, and custom page sizes. Headers and footers accept page-number placeholders and per-page configuration via slots. Text and image watermarks support under/over layering and per-page control.

Custom fonts and multilingual text

Accepts TTF font files via fontBytes, with support for subsetting, bold, italic, icon fonts, and language-based Unicode-range fallback via langFontConfig. The live demo validates Chinese, English, and RTL text in a single export, with each character remaining selectable in the output.

PDF compression, encryption, and multiple output formats

Supports DEFLATE compression, user and owner passwords, and PDF permission flags. Returns a Blob, Uint8Array, or triggers a direct browser download via the downloadPDF helper, fitting pipelines that use the File System API or a fetch-based upload endpoint.

Features

  • Vector PDF output with selectable text
  • Fully client-side rendering with no document upload
  • Paginated documents with headers, footers, and watermarks
  • Custom fonts and multilingual text
  • PDF compression, encryption, and multiple output formats

How to install

Install dompdf.js via npm for module-based projects.

npm install dompdf.js

Recommended for this setup

Strengths

  • MIT license with no per-document cost: The library is MIT licensed, so you can embed it in commercial products without restriction and pay only for the resources your users' browsers consume. Unlike PDFShift, DocRaptor, or Doppio, there is no per-page or per-request billing at any scale.
  • Approximately two seconds for 500-page documents: Benchmarked at about two seconds for a 500-page document in representative tests, with the architecture scaling to tens of thousands of pages for extreme workloads. Web Workers handle the rendering pipeline, keeping the main thread unblocked throughout the export.
  • No server infrastructure to deploy or maintain: Because rendering runs in the browser, there is no PDF generation service to deploy, scale, or operate. Adding dompdf.js is an npm install; you remove a server-side dependency rather than adding one, reducing operational surface area for teams self-hosting their applications.

Trade-offs

  • Browser-only: no Node.js server-side support: The export APIs depend on browser DOM and Web APIs and cannot be called in a plain Node.js environment. Teams that need server-side PDF generation for headless pipelines, scheduled reports, or email attachments generated without a browser session cannot use dompdf.js for those workflows.
  • CSS rendering depends on the browser, not the library: dompdf.js reads geometry already computed by the browser and is not a complete rendering engine. Complex CSS filters, animations, video, and some advanced CSS properties may be rasterized or degraded in the output. Rendering fidelity depends on the browser version and CSS feature support at export time.

Tech stack

Languages
TypeScript, JavaScript, Rust, HTML, Python
Frameworks
—
Databases
—
Tooling
Rollup

FAQ

Does dompdf.js require a backend server to generate PDFs?

No. The entire PDF generation pipeline runs in the user's browser via Web Workers and WebAssembly. No document content is sent to a server. You add the package via npm or a CDN script tag and call it directly from browser JavaScript.

Is the text in generated PDFs selectable and searchable?

Yes. dompdf.js produces vector PDF objects from the browser's computed DOM geometry, so text in the output is selectable, searchable, and copyable. This is different from screenshot-based PDF libraries that rasterize the page into an image and make text non-selectable.

What browsers does dompdf.js support?

The library requires a modern browser with Web Workers, WebAssembly, Blob, and related Web APIs, all of which are standard in current major browsers. It cannot be called in a plain Node.js environment because the export APIs depend on browser DOM APIs.

Can I use custom fonts and export non-Latin characters?

Yes. Load a TTF font file and pass the bytes via fontConfig with a fontBytes field. The library supports font subsetting, bold, italic, icon fonts, and language-based Unicode-range fallback via langFontConfig. The live demo validates Chinese, English, and mixed-language text in a single export, with each character remaining selectable in the output.

Is dompdf.js free for commercial use?

Yes. dompdf.js is MIT licensed, which permits use in commercial products without restriction or licensing fees. There are no per-page or per-document costs; you pay only for the device resources your users' browsers consume during export.

Similar tools

More in Web Developers