Tips & Tricks

How to OCR a PDF and Export the Recognized Text as a Markdown File

You OCR a PDF and the recognized text appears in a text box inside your PDF editor. You can read it. You can copy and paste it. But what you actually want is the text in a Markdown file, with headings formatted as hashes, lists as asterisks, links as bracket-parenthesis pairs, and paragraphs separated by blank lines. Markdown is the lingua franca of developers, technical writers, bloggers, and anyone who needs clean, portable text that can be dropped into a static site generator, a note-taking app, or a code repository.

Going from a scanned PDF to a Markdown file is a two-step pipeline: OCR recognizes the text, and then a formatting step converts that recognized text into Markdown syntax. Each step has tool choices that affect the quality of the final output.

How to OCR a PDF and Export the Recognized Text as a Markdown File

Step 1: OCR the PDF to Extract Recognized Text

The OCR step is the same as making any PDF searchable. Use an OCR PDF tool to process the scanned pages. The tool adds a text layer to each page. For Markdown export, you want the OCR output in a format that preserves as much structural information as possible: which text is a heading, which text is body, which text is part of a list or a table. Standard OCR engines output plain text, which loses all structural information. A heading and a body paragraph become indistinguishable blocks of text separated by line breaks.

For best results, use an OCR engine that supports layout-aware text extraction. These engines analyze the spatial arrangement of text on the page and can distinguish between headings, body text, captions, and footnotes based on font size, position, and proximity to other elements. The more structural information the OCR engine captures, the cleaner the Markdown conversion will be. Adobe Acrobat Pro's Export To feature includes a "Text with Formatting" option that preserves some structural cues. The OCR engine preserves font size and position metadata that downstream conversion tools can use to infer heading levels and paragraph breaks.

WukongPDF

Try PDF OCR

No installation needed. Works directly in your browser.

Get Started โ†’

Step 2: Convert the Recognized Text to Markdown

Once the PDF has a text layer, the conversion to Markdown can proceed through several paths. The simplest is a direct export from a PDF editor that supports Markdown as an output format. WukongPDF's export options include Markdown as a target format when the PDF has been OCR-processed. Select Markdown as the output format, and the tool generates a .md file with the recognized text formatted according to Markdown conventions: lines beginning with larger fonts become hash-prefixed headings, indented lines become list items, and regular paragraphs are separated by blank lines.

If a direct Markdown export is not available, the pipeline is: export the recognized text to a rich text format that preserves formatting, such as RTF or HTML, then convert that intermediate format to Markdown using a conversion tool. Pandoc, the universal document converter, handles this pipeline well. Export the text from the PDF as HTML, then run: pandoc input.html -f html -t markdown -o output.md. Pandoc translates HTML heading tags to Markdown hashes, HTML list tags to Markdown list markers, and HTML link tags to Markdown link syntax. The quality of the output depends on the quality of the HTML export from the PDF. If the PDF export produces clean, well-structured HTML, Pandoc produces clean Markdown. If the export produces messy HTML with inline styles and non-semantic tags, the Markdown will be correspondingly messy.

Cleaning Up OCR Errors in the Markdown Output

OCR errors in the recognized text pass through to the Markdown output unchanged. Common errors include confused characters like "cl" recognized as "d," "rn" recognized as "m," and "1" recognized as "l," especially in smaller font sizes or lower-quality scans. A review pass through the Markdown file to catch these errors is essential if the text will be published or shared.

Most code editors and Markdown editors include spell-check functionality that highlights unrecognized words, making OCR errors easy to spot. Work through the highlighted words and correct them against the original PDF. Pay particular attention to proper nouns, technical terms, and numbers, which are the most likely to be incorrectly recognized and also the most damaging if published incorrectly. A financial report where OCR recognized "$123,000" as "$128,000" contains a material error that automated spell-check will not catch because both are valid number formats. Manual verification of critical values against the source document is the only reliable safeguard.

Preserving Images and Tables in the Markdown Conversion

Markdown handles images by referencing external files: ![alt text](path/to/image.png). When converting a PDF to Markdown, the images in the PDF need to be extracted and saved as separate files, and reference links inserted into the Markdown text at the correct positions. WukongPDF's PDF Export to Markdown includes image extraction as part of the conversion. Each image in the PDF is saved as a PNG or JPEG file in a folder alongside the Markdown file, and the Markdown text contains the appropriate image reference tags.

Tables are more challenging. Markdown tables use a pipe-and-dash syntax that is easy for humans to read but difficult for automated converters to generate from PDF table data because PDFs do not store tables as structured data. They store characters at positions. The converter must reverse-engineer the table grid from character positions, which produces imperfect results for complex tables with merged cells, multi-line cell content, or unequal column widths. Simple grid tables with uniform columns and single-line cell content convert reliably. Complex tables may need manual restructuring in the Markdown output. If a table converts poorly, consider exporting it as a separate image rather than as Markdown table syntax. A cleanly readable image of a complex table is more useful than garbled Markdown that renders as misaligned columns.

Putting the Markdown File to Use

The resulting Markdown file opens in any text editor, note-taking app like Obsidian or Notion, static site generator like Hugo or Jekyll, or code editor like VS Code. From Markdown, you can generate HTML for a website, PDF for distribution, DOCX for Word processing, or simply keep the text in a searchable, version-controllable plain text format that will be readable for decades.

The value of this pipeline is most apparent with archival material. Old scanned reports, historical documents, out-of-print publications, all become not just searchable but transformable. A scanned report from 2005 becomes a Markdown file that can be edited in a modern editor, converted to a website, quoted in a blog post, or analyzed programmatically. The PDF Format that locked the text inside an image for 20 years no longer constrains how the content can be used.

WukongPDF

Try PDF OCR

No installation needed. Works directly in your browser.

Get Started โ†’