Table of Contents

๐Ÿ‘‰ Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/document-intelligence/document-parsing/structured_document_parser

AI Document Parsing for C# .NET Applications (PDFs, Scans and Images)


๐ŸŽฏ Purpose of the Demo

Structured Document Parser showcases DocumentParser, LM-Kit.NET's AI document parser. It turns a PDF, a scan or an image into what downstream systems need: every page as elements in reading order, each with its role, its position, its confidence and its typed content. Tables come back as HTML with their merged cells, formulas as LaTeX, and charts as the data they plot. One parse exports to Markdown, lossless JSON, semantic HTML and DocLang, the open AI-native document standard of the LF AI and Data Foundation.

The sample shows how to:

  • Create a parser with one setting, the ParsingEffort level.
  • Download the parser's models ahead of time with DocumentParser.GetModelCards.
  • Report live progress with the PageParsed event and parse a page range.
  • Read the typed elements of each page (ParsedPage.Elements).
  • Export with ToMarkdown, ToJson, ToHtml, ToDocLang, and keep figure pictures with IncludeFigureImages.

๐Ÿ‘ฅ Target Audience

  • Document platform engineers who need structure, not just text, from PDFs and scans.
  • RAG and search builders who want tables and charts to survive ingestion.
  • Data teams feeding parsed documents into pipelines in any language through JSON.
  • Regulated organizations that cannot send documents to a cloud parser.

๐Ÿš€ Problem Solved

  • Structure survives. Headings keep their level, tables keep their spans, charts become data.
  • Positions for every element. Bounds and reading order make citations and highlighting possible.
  • Standard formats. JSON with a published schema, HTML, and DocLang, instead of a proprietary result.
  • Private by construction. The models run in your process; no page leaves the machine.

๐Ÿ’ป Demo Application Overview

A console application: choose the effort level and whether to keep figure pictures, then enter documents one by one. For each, the demo prints the element tree of every page and writes all exports to a <document>_parsed folder.


โœจ Key Features

  • Effort levels Low, Medium, High, with the models chosen and verified by the parser.
  • Element categories: title, text, table, formula, figure, captions, footnotes, header, footer.
  • Charts as data tables, with their title, legend and panels.
  • Five outputs: .md, .json, .html, .dclg, and a .dclx DocLang archive with the pictures.

Example Output

--- Page 11  (612 x 792 Points)
    0  Figure          chart (data table)   [53,70 547,329] 100 %  | Characteristic | Tracing | SFX | V8 |
    1  FigureCaption   text                 [51,351 560,422] 100 %  **Figure 10.** Speedup vs. a baseline...
    2  Text            text                 [51,441 294,493] 100 %  In particular, the bitops benchmarks...

Exported Markdown, JSON, HTML and DocLang to reports\paper_parsed

2 page(s), 36 elements in 14.1 s.

๐Ÿ—๏ธ Architecture

  PDF / scan / image
          โ”‚
          โ–ผ
  DocumentParser(effort)  โ”€โ”€  models from GetModelCards(effort), verified
          โ”‚   PageParsed events
          โ–ผ
  ParsedDocument โ”€โ”€ pages โ”€โ”€ elements (category, bounds, reading order, content)
          โ”‚
          โ”œโ”€โ”€ ToMarkdown()   โ†’ .md
          โ”œโ”€โ”€ ToJson()       โ†’ .json   (FromJson reads it back)
          โ”œโ”€โ”€ ToHtml()       โ†’ .html
          โ”œโ”€โ”€ ToDocLang()    โ†’ .dclg
          โ””โ”€โ”€ SaveDocLangArchive() โ†’ .dclx  (with IncludeFigureImages)

โš™๏ธ Getting Started

๐Ÿ“‹ Prerequisites

  • .NET 8.0 or later
  • A GPU is recommended (about 6 GB of VRAM at Medium); the parser also runs on the CPU
  • About 2.5 GB of disk for the models, downloaded on first run

๐Ÿ“ฅ Download the Project

git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/document-intelligence/document-parsing/structured_document_parser

โ–ถ๏ธ Run the Application

dotnet run

๐Ÿ”ง Troubleshooting

Problem Fix
The first run pauses for minutes The models are downloading; the demo shows the progress
Parsing is slow Use Low, parse a page range, or run on a GPU
A figure has no data table It is a picture (a photo, a diagram); its caption and optional description are kept

๐Ÿš€ Extend the Demo


๐Ÿ“š Additional Resources

Share