DoclingSharp is a .NET 8 client library for interacting with Docling (version >1.0.1). It provides two core features:
- DoclingClient – Extracts content from documents uploaded as
IFormFileobjects via the Docling API. - DocumentChunker – for splitting document content into manageable chunks suitable for embeddings or other processing.
Install via NuGet:
dotnet add package DoclingSharpIn your Program.cs or Startup.cs:
builder.Services.AddDocling(c =>{c.DoclingAddress=newUri("http://localhost:5001");c.ChunkMaxCharacters=2048;c.ChunkCharacterOverlap=128;});This sets up both DoclingClient and DocumentChunker with your preferred configuration.
In a controller, service, or background task:
// Extract content from an uploaded IFormFilevarresult=await_doclingClient.ExtractDocumentContentAsync(file);// Split the content into chunks for embedding or further processingvardocumentChunks=_documentChunker.ChunkDocument(result.Markdown);// Pass the chunks to your embedding engine- ExtractDocumentContentAsync: Works with IFormFile inputs for PDFs, DOCX, and other supported formats. Returns structured DoclingResult including Markdown, plain text, JSON, and HTML.
- DocumentChunker: Splits documents into overlapping chunks to ensure no content is lost between segments, making it ideal for embedding workflows.
- Fully integrated with IHttpClientFactory and IOptions for clean dependency injection.
- Configurable chunk sizes and overlap.
varoptions=newDoclingOptions{DoclingAddress=newUri("http://localhost:5001"),ChunkMaxCharacters=2048,ChunkCharacterOverlap=128};varhttpClientFactory= ...;// get via DI or manuallyvardoclingClient=newDoclingClient(httpClientFactory,Options.Create(options));vardocumentChunker=newDocumentChunker(options);varfile=File.OpenRead("example.pdf");varresult=awaitdoclingClient.ExtractDocumentContentAsync(file);varchunks=documentChunker.ChunkDocument(result.Markdown);- .NET 8+
- Docling API >1.0.1
- Microsoft.Extensions.Http and Microsoft.Extensions.Options