---
title: "Convert a scanned page to Markdown in C#"
url: https://recursiveai.org/oneocr/cookbook/convert-scanned-page-to-markdown/
description: "Convert a page image to Markdown in C# with headings and pipe tables. Run the example and inspect the actual OCR output and structure."
version: "1.0.0"
---

# Convert a scanned page to Markdown in C#

**OneOcr** is a free, open-source OCR library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneOcr) · [GitHub](https://github.com/recursive-ai-oss/oneocr-csharp) · [Docs](https://recursiveai.org/oneocr/docs/) · [Download example (.zip)](https://recursiveai.org/oneocr/cookbook/convert-scanned-page-to-markdown/convert-scanned-page-to-markdown.zip)

The zip includes `page.png`, a stock report.

```shell
dotnet add package RecursiveAI.OneOcr
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneImage;
using OneOcr;
var engine = OcrEngine.LoadBundled();
File.WriteAllText("page.md",
    Image.Load("page.png").ToMarkdown(engine));
```

Unzip [the example](https://recursiveai.org/oneocr/cookbook/convert-scanned-page-to-markdown/convert-scanned-page-to-markdown.zip), then `dotnet run`.

Writes `page.md` (no console output):

```markdown
# STOCK REPORT

## Items ready for delivery.

| Product | Quantity |
| --- | --- |
| Paper | 12 |
| Pens | 24 |

Please check all quantities.

## Store paper in a dry room.

Contact the office for supplies.
```

## The full program

The input has a large “STOCK REPORT” title, “Items ready for delivery.”, a two-column Product/Quantity table containing Paper/12 and Pens/24, and three closing instructions. The output above shows all of those inputs, including the extra headings inferred from the layout.

```csharp
using OneImage;
using OneOcr;
var engine = OcrEngine.LoadBundled();
var image = Image.Load("page.png");
string markdown = image.ToMarkdown(engine);
File.WriteAllText("page.md", markdown);
Console.Write(markdown);
```

The full program also prints the Markdown shown above. The `OneImage` namespace comes from a dependency installed with `RecursiveAI.OneOcr`.

Unreadable image bytes raise `OcrFormatException`; a readable image with no recognized text produces an empty Markdown string.

## Variations

Keep running headers and footers, which are normally omitted.

```csharp
using OneImage;
using OneOcr;
var engine = OcrEngine.LoadBundled();
var image = Image.Load("page.png");
Console.Write(image.ToMarkdown(engine,
    new MarkdownOptions { IncludeHeadersAndFooters = true }));
```

On this sample, the output is identical to the Markdown printed above; no running header or footer was detected.

## Related recipes

- [Extract a table from an image](https://recursiveai.org/oneocr/cookbook/extract-table-from-image/)
- [OCR a multipage TIFF](https://recursiveai.org/oneocr/cookbook/ocr-multipage-tiff/)
- [Save OCR results as JSON](https://recursiveai.org/oneocr/cookbook/page-json/)

## The short answer

Load the scan as a OneImage `Image`, create `OcrEngine.LoadBundled()`, and call `image.ToMarkdown(engine)`. Save the returned string with `File.WriteAllText`. The full example writes a Markdown file, not an image embedded in a Markdown document. Its pipe table contains the recognized cells, so you can edit the quantities without modifying the original scan.

This is a local, rule-based Markdown writer over OCR results. It does not use a language model to rewrite the document. The [Markdown specification](https://recursiveai.org/oneocr/docs/markdown/) describes which layout features are represented and which are not.

## Can an image be converted to Markdown?

Yes, but the conversion has two distinct parts: recognize the words and their layout, then serialize that layout as Markdown. The sample demonstrates headings, paragraphs and a table. Its title becomes `# STOCK REPORT`; the first table row becomes the Markdown header row, followed by the separator and data rows. The writer uses the first row as a header convention, not as a guarantee that the document’s author intended it as one.

Review the inferred structure as well as the words. In this run, “Items ready for delivery.” and “Store paper in a dry room.” become second-level headings. They are ordinary sentences in the generated input. The program has not changed their wording, but its layout interpretation is imperfect. If your application needs authoritative section boundaries, review the result instead of treating every `#` marker as a verified document label.

A table cell spanning several rows or columns places its text at the top-left position; the covered positions stay empty. This keeps cell text available, but a Markdown pipe table cannot reproduce merged-cell geometry. Text containing a pipe is escaped so that it does not accidentally start another column.

The writer does not emit bold or italic emphasis, links, embedded images, code blocks, footnotes or math. A figure contributes text recognized inside it, not a saved image. Multi-column material follows the page’s reading order rather than retaining a side-by-side page layout. Choose this output for editable text with basic structure, not for a visual copy of the scan.

## How to convert image to text using OCR?

The same recognition engine can produce plain text, structured pages or Markdown. Use plain text when all you need is the wording. Use Markdown when a table or heading should survive into an editor. Keep the structured page model when you need word coordinates, confidence, diagnostics or the original table spans. Markdown deliberately leaves those details out.

Start with an upright, legible page image and compare the output with it. A recognized amount in a table remains recognized text; Markdown does not validate the number or its meaning. The sample’s simple generated image lets you check the expected cells directly. Real scans can introduce blur, noise and skew that change the transcription or structure.

Running headers and footers are omitted by default. The variation keeps blocks assigned those roles, but it does not invent a header if none was detected. Page-number removal is a separate Markdown option. For multipage images, the image extension reads every frame; use `OcrPages` when you need to inspect each page and its diagnostics separately before exporting.
