๐ 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
ParsingEffortlevel. - Download the parser's models ahead of time with
DocumentParser.GetModelCards. - Report live progress with the
PageParsedevent and parse a page range. - Read the typed elements of each page (
ParsedPage.Elements). - Export with
ToMarkdown,ToJson,ToHtml,ToDocLang, and keep figure pictures withIncludeFigureImages.
๐ฅ 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.dclxDocLang 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
- Store the JSON and reload it later with
ParsedDocument.FromJson, without the models. - Feed the pages into a RAG index: see the Parsed Document RAG demo.
- Harvest every chart as CSV: see the Chart Data Harvester demo.