Convert documents for RAG pipelines

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Markdown MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-markdown -- dnx GroupDocs.Markdown.Mcp --yes
Folders, licensing and more →

Retrieval-augmented generation (RAG) systems need documents in a clean, structured text format for chunking and embedding. Markdown is ideal — it preserves document structure (headings, lists, tables) while being easy to parse.

flowchart LR
    A["PDF / DOCX / XLSX"]
    B["GroupDocs.Markdown"]
    C["Markdown"]
    D["Text Chunking"]
    E["Vector Embeddings"]
    F["LLM Query"]
    A --> B --> C --> D --> E --> F

Basic conversion for RAG

using GroupDocs.Markdown;

// Convert document to Markdown — skip images for text-only RAG
var options = new ConvertOptions
{
    ImageExportStrategy = new SkipImagesStrategy(),
    Flavor = MarkdownFlavor.CommonMark
};

string markdown = MarkdownConverter.ToMarkdown("professional-services.pdf", options);

// Split into chunks by headings
string[] chunks = markdown.Split(
    new[] { "\n## ", "\n# " },
    StringSplitOptions.RemoveEmptyEntries);

foreach (string chunk in chunks)
{
    // Send each chunk to your embedding model
    Console.WriteLine($"Chunk ({chunk.Length} chars): {chunk.Substring(0, Math.Min(80, chunk.Length))}...");
}

professional-services.pdf is a sample file used in this example. Click here to download it.

Chunk (7889 chars): 

**Professional Services**

A catalog of engagements offered by Meridian Ou...

Download full output

Batch processing a document library

using GroupDocs.Markdown;

var options = new ConvertOptions
{
    ImageExportStrategy = new SkipImagesStrategy()
};

string[] files = Directory.GetFiles("documents", "*.pdf");

foreach (string file in files)
{
    try
    {
        string markdown = MarkdownConverter.ToMarkdown(file, options);
        string outputPath = Path.ChangeExtension(file, ".md");
        File.WriteAllText(outputPath, markdown);
        Console.WriteLine($"Converted: {file}");
    }
    catch (GroupDocsMarkdownException ex)
    {
        Console.WriteLine($"Skipped {file}: {ex.Message}");
    }
}
documents/business-plan.md (7 KB)

Download full output