A scanned report may contain information you want to edit or add to your documentation. With OCR, you can recognize text in the image and save it as Markdown instead of retyping it.
In this article, you’ll learn how to convert a PNG or JPG image to Markdown in C# using Aspose.OCR for .NET. You’ll also see how the output can include recognized tables and detected images.
C# OCR Library for Image-to-Markdown Conversion
Aspose.OCR for .NET lets you recognize text in images and save the results in several formats, including Markdown. For this tutorial, use version 26.10.0 or later. Version 26.10 introduced the DOCUMENT_LAYOUT setting used in the example and enhanced Markdown export with layout information.
Install the package in your .NET console project using the following command:
dotnet add package Aspose.OCR --version 26.10.0
You’ll also need a readable PNG or JPG image and permission to write the output files. To follow the example, place an image named report.png in your project directory.
The trial version limits the amount of recognized text. To remove this restriction during evaluation, you can request a temporary license and apply it before recognition. See the licensing documentation for details.
Convert an Image to Markdown in C#
The following steps show how to recognize an image and save the result as Markdown:
- Create an instance of the
AsposeOcrclass. - Create an
OcrInputobject for a single image and add the image file. - Set
DetectAreasModetoDOCUMENT_LAYOUTin aRecognitionSettingsobject. - Call the
Recognizemethod to process the image. - Save the results using
OcrOutput.SaveandSaveFormat.Md.
For this example, use an image of a report containing a heading, text, a table, and an illustration. Replace the contents of Program.cs with the following code:
using Aspose.OCR;
// Create the OCR engine.
AsposeOcr recognitionEngine = new AsposeOcr();
// Add the image to the input.
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add("report.png");
// Enable document layout detection.
RecognitionSettings settings = new RecognitionSettings
{
DetectAreasMode = DetectAreasMode.DOCUMENT_LAYOUT
};
// Recognize the image.
OcrOutput results = recognitionEngine.Recognize(input, settings);
// Save the recognition result as Markdown.
results.Save("report.md", SaveFormat.Md);
Run the application from the project directory:
dotnet run
The application reads report.png and saves the recognition result as report.md. Both paths are relative to the application’s current working directory. For a JPG image, change the input path to your JPG file; the recognition and export steps remain the same.
DOCUMENT_LAYOUT detects document elements that can be used to organize the Markdown output. The result depends on the image and the content recognized, so review the output against the original. The example follows the Aspose.OCR 26.10 release notes.
Review the Generated Markdown
Open report.md in a text editor or Markdown viewer. You can edit the recognized text and adjust its structure as needed. When the OCR engine recognizes a table, the export can represent it as a Markdown table.
The following excerpt illustrates Markdown table and image syntax. It is not actual OCR output; the content and paths in your result will depend on the source image and recognition:
## Quarterly Report
| Product | Sales |
| --- | --- |
| Product A | 120 |

When an image is detected and included in file output, Aspose.OCR can save it in a document-specific images directory next to the generated Markdown and add a reference to it. Keep the Markdown file and its referenced images together, preserving the paths in the file, so the images can be displayed in your Markdown viewer.
Markdown describes content and structure; it does not necessarily reproduce the exact appearance of the original report.
Tips for Better OCR Results
- Use a clear source image. Text and table borders should be readable in the original image.
- Choose the appropriate recognition language. Set
RecognitionSettings.Languagewhen needed. Some languages require an additional recognition model; see the language documentation. - Check important details. Compare names, numbers, table cells, and reading order with the source image.
- Verify image references. Open the Markdown in a viewer and check that extracted images appear.
- Test representative documents. Complex tables and layouts may need manual corrections, so review examples before using the output in an automated workflow.
Frequently Asked Questions
Can I convert both PNG and JPG images to Markdown in C#?
Yes. Add the PNG or JPG file to OcrInput, recognize it, and save the results with SaveFormat.Md.
Can the Markdown output contain tables?
Yes. Recognized tables can be exported as Markdown tables. The result depends on the source image and how the table is recognized.
Where are detected images saved?
For file output, detected images can be saved in a document-specific images directory next to the generated Markdown. The Markdown content references those files.
Does the Markdown file preserve the original page layout exactly?
No. Markdown represents content and structure differently from a page image. Review the generated file and adjust the structure where needed.
Conclusion
Use this workflow as a starting point for converting your own reports or scanned pages to Markdown. Before adding the results to your documentation, compare the text, tables, and image references with the original.
For more information, see the recognition documentation. If you need help, visit the Aspose.OCR support forum.
