MarkPrep
All posts
Published · Updated · 6 min

Scanned PDF to Markdown: Getting Text Out of an Image

Converting a scanned PDF to Markdown starts with OCR (optical character recognition), which reads the text from the page images. Only then can the text become Markdown. A quick test tells you which kind of PDF you have: try to select a sentence with your cursor. If the text highlights, it is a digital PDF with a real text layer, and converting it is easy. If your cursor draws a box and nothing highlights, you have a scan, a stack of images that look like a document.

What OCR does

For a digital PDF, conversion is close to transcription, because the text is already there. For a scan, OCR has to rebuild the text from an image. It separates characters from the background and copes with smudges, stains and the slight blur of a phone photo of a page. So scanned conversion is slower and less accurate than digital conversion.

OCR is accurate on a clean, straight, high-resolution scan. Accuracy drops as the input gets worse. A crisp 300 DPI scan reads well, and a dim photo of a crumpled receipt does not.

How MarkPrep reads a scanned PDF

MarkPrep's OCR is switched on by default. It only runs on PDF pages that have no text layer. Digital pages are read directly, so a mixed PDF gets OCR only where it needs it. For each scanned page, MarkPrep:

  1. Renders the page larger, at about 200 DPI, so small text has more pixels to work with.
  2. Converts it to greyscale, then to pure black and white (a step called thresholding), so the text stands out from the background.
  3. Reads it with Tesseract, an open-source OCR engine, running locally in your browser.

The OCR reads English. MarkPrep doesn't straighten skewed pages, so scan or photograph pages as straight as you can. Handwriting and mathematical equations don't come out reliably.

What to check in the output

Spot-check these parts of the output against the original:

  • Numbers and names first. A misread 8 for a 3 in a contract or invoice matters far more than a typo in a paragraph.
  • Tables. Columns in a scan are the hardest thing to rebuild. Check they didn't collapse.
  • Low-confidence pages. MarkPrep flags each page that OCR read with confidence below 75%, so you know where to look instead of re-reading everything.

The privacy catch

Scans are often sensitive documents, such as signed contracts, medical forms, ID pages and handwritten notes. OCR has long been a cloud service, where you upload the image, a server reads it and you get text back. For a confidential scan, that is a real exposure.

In MarkPrep, Tesseract runs as WebAssembly inside your browser, on your own machine. It is slower than OCR on a server, but it lets you convert scans you can't upload. To confirm it, watch the browser's Network tab. During conversion, no request carrying your file leaves the page.

Once it's text, it's like any other document

Once OCR has turned your scan into Markdown, it behaves like any converted document. You can check its token count, see whether it fits your model, and chunk it if it doesn't.

Drop the scan onto the scanned PDF to Markdown converter, then check the numbers, the tables and any flagged pages against the original. For single photos or screenshots of a page, use image to Markdown, which runs the same Tesseract OCR on PNG, JPG and WEBP files.

Try it on your own file

Convert a document and watch the token counter. It's free, needs no account and uploads nothing.