Generate selectable, searchable, vector-based PDFs from HTML.
Many HTML-to-PDF libraries work by taking a screenshot of the page and placing that image inside a PDF.
It looks like a PDF, but the text is no longer real text. You cannot properly search, select, or copy it, and the file can become much larger than necessary.
That is why I built html2realpdf.
Why real text matters
html2realpdf keeps text as text, links as links, and supported graphics as vectors.
The resulting PDF is:
- Selectable
- Searchable
- Sharp at every zoom level
- Easier for software and AI tools to read
- Often smaller than a screenshot-based PDF
Avoid unnecessary OCR costs
If your application already has the original HTML and text, it should not need to convert everything into an image and later use OCR to recover that same information.
With a real PDF, document-processing tools can extract the text directly.
This can reduce OCR or vision-processing costs, improve accuracy, and make the entire process faster.
OCR is still useful for scanned documents, but it should not be necessary for a PDF generated by your own application.
Switching from html2pdf.js is simple
html2realpdf includes an API compatible with common html2pdf.js workflows.
In many projects, you only need to change the imported library:
// Before
import html2pdf from "html2pdf.js";
// After
import html2pdf from "@imggion/html2realpdf";
The rest of the code can remain the same:
html2pdf()
.from(element)
.save();
If your configuration uses options specific to screenshots or html2canvas, those options may need to be removed.
Standard PDF generation, page settings, margins, and page breaks are supported through the compatibility API.
A quick benchmark
One recorded run used the same deterministic 30-page report with both libraries:
| Engine | First PDF | Warm render | File size | Pages | Output |
|---|---|---|---|---|---|
html2realpdf |
1595.9 ms | 1451.2 ms | 441.1 kB | 30 | Native, selectable PDF |
html2pdf.js |
2124.6 ms | 1952.4 ms | 3.11 MB | 30 | Raster image PDF |
In this test, html2realpdf produced:
- A 33.1% faster first PDF
- A 34.5% faster warm render
- An 85.8% smaller file
- Native and selectable text instead of rasterized pages
Benchmarks depend on the document and the machine, but the main difference remains: html2realpdf stores real text and vector graphics instead of full-page screenshots.
Built for the browser
html2realpdf is written in Zig, compiled to WebAssembly, and packaged with a typed TypeScript API.
It works directly in the browser with:
- Plain HTML elements
- HTML strings
- React refs
- Vue template refs
The project is still growing and does not support every CSS feature yet, but the goal is simple:
Generate real, machine-readable PDFs from HTML, not screenshots.

Top comments (0)