Urgent.News

the world's headlines, one feed

Tech

OCR and sign a PDF entirely in the browser — no upload, no server

Most "free online PDF" tools quietly upload your document to a server. For a signed contract or a scanned ID, that's the whole problem. So I built two tools that don't: an OCR PDF that turns a scanned PDF into a searchable one, and a Sign PDF that adds your signature — both running 100% in the browser . Nothing is uploaded; close the tab and it's gone. Here's how each one works, plus the part…

Two innovative web-based tools enable the complete processing of scanned PDFs and adding signatures, all without any server interaction or file uploads. These solutions address concerns about privacy and security associated with uploading documents to third-party servers for editing or signing.

The OCR PDF tool converts scanned documents into searchable PDFs entirely within the browser. It transforms image-based scanned PDFs into text-searchable documents by performing Optical Character Recognition (OCR). The process involves rendering each page of the PDF onto a canvas using the pdf.js library. Next, the Tesseract.js library is employed to recognize the characters within the image and create an invisible text layer that overlays the original page.

This text layer is then integrated into a new searchable PDF using the pdf-lib library, which draws the page image followed by each recognized word at its bounding box position. The tool also exports the plain text of the recognized document for additional use.

On the other hand, the Sign PDF tool allows users to add their signatures to PDF documents, again without any need for server interaction. Users can either draw a signature directly onto a canvas with point event capabilities, type their name using a pre-installed script font, or upload a signature image in PNG format. Regardless of the method chosen, the signature is trimmed of any extraneous margins, converted to PNG format, and then positioned onto the PDF document.

The tool ensures the signature is accurately mapped to the desired location on the page, maintaining its appearance and legibility. It also provides users with the ability to resize and reposition the signature as needed before it is permanently embedded into the PDF.

Both tools emphasize user privacy and data security by operating entirely within the user's browser environment. This ensures that documents are never uploaded to a server, reducing the risk of unauthorized access or data exposure. Additionally, the tools employ WebAssembly (WASM) for the OCR functionality, which runs within a Web Worker, further isolating the processing from the main browser thread to enhance performance.

The implementation also takes into account strict Content Security Policy (CSP) restrictions that might otherwise hinder the use of WebAssembly. The solution involves vendoring the required WebAssembly modules to ensure they are served from the same origin, thereby bypassing the need for unsafe-eval, which can be a security vulnerability.

This meticulous approach to security and functionality enables these tools to provide a seamless and secure user experience for PDF processing and signing needs.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written; read the original for the full account.

Read the original at dev.to →

More in Tech