DEV Community

Cover image for There are around 10 independent PDF engines, and I built a new one from scratch.
KeyPDF
KeyPDF

Posted on

There are around 10 independent PDF engines, and I built a new one from scratch.

I'm a student who mostly built little apps for myself. About 14 months ago I needed to edit a random PDF and couldn't find a good web tool that actually edits them. It made me wonder: billions of people use PDFs for work, school, and legal documents, so why can almost no web service truly edit them?

So I tried to build one, and failed. I didn't understand why it was so hard. I tried combining pdf.js and jsPDF but kept hitting walls. Then it clicked: most JavaScript PDF libraries only do two things: create or view. Neither handles editing existing text. I thought I could build a layer in between, but I got nowhere, especially once I tried changing font styles, sizes, and colors.

After weeks of research, I concluded that to edit PDFs in the browser without a server, I'd have to build something genuinely new. So I read the PDF spec and started building an engine from scratch, beginning with simple PDFs (standard font encoding, no compression) and slowly adding codecs, compression types, and font support.

After around 7 months, it could render pretty well but still couldn't edit. A month later I got basic editing working, then hit a wall saving edited PDFs (endless visual bugs). After more digging, I finally understood how to save properly.

Then came the hardest part: textbox recognition. A PDF stores text and coordinates but not the grouping or structure. So I spent weeks literally highlighting textboxes across many PDFs by hand, looking for general grouping rules. After 2 months, I had editing with textbox grouping.

Somewhere in there I also spent months implementing JavaScript support in the engine, and I even got DOOM running on it: https://youtu.be/gHoBMYMVn5s

Once the core worked, I focused on design, moving from a bloated debug UI to a clean interface (with a lot of Figma and Photoshop).

Tools I've built from scratch so far: direct text editing, redaction (text and area), annotation, form filling, page organization, and metadata editing.
You can try it here: KeyPDF.net
Happy to answer anything about how PDF parsing, rendering, fonts, or editing actually work under the hood. AMA.

Top comments (0)