---
title: "Scan Documents"
year: "2025"
motto: "Document Scanner App"
description: "Scan Documents is a web application that allows users to digitalize their documents using any photo or PDF file, and export them in different formats and displays."
stack: ["javascript", "typescript", "nodejs", "hono", "react", "nextjs", "cloudflare"]
website: "https://web.archive.org/web/20250718042700/https://scan-documents.com/"
url: "https://rolandoandrade.me/projects/scan-documents/"
author: "Rolando Andrade"
---

# Scan Documents

> Document Scanner App

Scan Documents is a web application that allows users to digitalize their documents using any photo or PDF file, and export them in different formats and displays.

Year: 2025. Stack: javascript, typescript, nodejs, hono, react, nextjs, cloudflare. Website: https://web.archive.org/web/20250718042700/https://scan-documents.com/

My archive was a disaster. Papers everywhere. Certificates from years ago at risk of getting lost. Important documents spread across drawers. In December, I needed to digitize everything for possible immigration paperwork. That need became Scan Documents.

I had tried other scanning apps. They all seemed made for quick, single page scans. They are great for a receipt. A contract with many pages is painful. You take a photo, fix the corners by hand, pick the colors, export, convert to PDF and merge it with another tool. Then you repeat that for every page.

I was frustrated enough to build my own.

## Built from my own problems

My own problems set the goals:

- Bulk upload. Drop hundreds of pages at once, with automatic edge detection and color adjustment.
- Many kinds of input. Accept camera photos, existing images or PDF files.
- Page organization. Drag and drop to reorder, delete bad scans and insert new pages anywhere.
- Several exports. PDF, individual images or eBooks.
- Offline first. No server needed, so sensitive documents stay on your device.

![The chaos that inspired Scan Documents](https://storage.rolandoandrade.me/blog/documents-chaos.webp)

## Everything runs in the browser

The app is a monorepo with four main parts. A React web app runs on Cloudflare Pages. A Hono backend runs on Cloudflare Workers. There is a public API for developers and a marketing site.

The whole scanning pipeline runs in the browser. The core features need no processing on a server. Your documents never leave your device unless you choose to sync them.

## Image processing with WebAssembly

This is the interesting part. The app does advanced image processing entirely in the browser with WebAssembly, a code format that runs almost as fast as native code.

**OpenCV.js** handles edge detection and perspective correction. When you upload a photo of a document, OpenCV finds the corners. Then it calculates the transform matrix that straightens the page.

**ONNX Runtime Web** runs machine learning models that detect documents. The model finds the edges of a document even in hard conditions, like cluttered backgrounds, shadows and curved pages.

**@jsquash libraries** encode and decode images. These WebAssembly versions of the JPEG, PNG and WebP codecs are fast and behave the same in every browser.

## Reading PDFs with Pdfium

Reading PDFs in the browser needs a real PDF engine. I use **@hyzyla/pdfium**, a WebAssembly port of the Chrome PDF renderer. With it, you can import existing PDFs, turn their pages into images and reorder them next to your scans.

## Workers keep the screen responsive

Heavy operations run in Web Workers, separate threads that keep the interface responsive:

- The preprocessing worker does edge detection, perspective transforms and color correction.
- The rendering worker renders PDF pages.
- The exporting worker generates PDFs and compresses images.

Each worker takes tasks from a queue. When you upload 100 pages, they process in parallel, and you can still scroll and drag pages while they do.

## Storing pages with Dexie

Memory was the first big challenge. Hundreds of high resolution images fill the browser's memory fast. The answer was the **Origin Private File System (OPFS)**, a private storage area each website gets, used through Dexie, a wrapper for IndexedDB.

Images load from disk only when needed. The visible pages stay in memory, and everything else lives in IndexedDB. You can process a 500 page document without crashing the browser.

## Page order with LexoRank

Reordering pages by drag and drop needs an efficient way to track positions. I use **LexoRank**, the algorithm Jira uses to order issues. LexoRank creates sortable strings, and you can always fit a new one between any two others. When you move one page, no other page needs a new number.

## Previews with Konva

The page preview uses **react-konva** to draw on a canvas. It handles zoom, panning and touch gestures smoothly. If the automatic detection missed something, users can adjust the crop area by hand.

## An API for developers

Beyond the app, I built a REST API for developers. The same scanning, edge detection and PDF generation are available over HTTP.

```bash
curl -X POST https://api.scan-documents.com/v1/files/upload \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@document.jpg"
```

The SDK includes an MCP server for AI assistants. Tools like Cursor can use it to explore the API and write integration code.

## Safari broke it first

OPFS behaves differently in each browser. Safari had quirks that broke my first version. The API exists there, but edge cases with file handles and concurrent access caused problems.

Fixing Safari took longer than I expected. Operations that worked in Chrome failed silently. In the end, I found workarounds that behave the same in every browser.

## Launch day

The app went live on March 10th, 2025. On the first day, more than 30 unique users came from several continents. That organic reach surprised me.

![Launch day analytics](https://storage.rolandoandrade.me/blog/scan-documents-analytics.webp)

## The browser can do the work

Heavy computing in the browser works. WebAssembly closes most of the speed gap with native apps. Users get privacy, because documents stay on their device, and convenience, because there is nothing to install.

The Web Worker design was a must. Without it, processing would freeze the interface. The queue grows naturally with the number of pages.

OPFS is underrated. It is fast, persistent and private. More web apps should use it instead of sending everything to servers.

[Scan Documents (archived)](https://web.archive.org/web/20250718042700/https://scan-documents.com/): The project is closed. This is a copy of its website saved by the Internet Archive.

* * *

Building Scan Documents solved my personal archiving problem. Seeing others use it for theirs makes the effort worthwhile.

[Book a call with Rolando](https://rolandoandrade.me/pricing/)
