# Split Documents into Page Chunks for RAG Pipelines in C# Split Word and PowerPoint files into page chunks for RAG ingestion with GroupDocs.Merger for .NET: cut by a page budget, write one file per page, or extract only the pages one question needs. {{< alert style="info" >}} 💡 Full working example available on GitHub: [split-documents-into-page-chunks-for-rag-dotnet](https://github.com/groupdocs-merger/split-documents-into-page-chunks-for-rag-dotnet) {{< /alert >}} ## Introduction Page chunking for RAG ingestion is a GroupDocs.Merger capability for .NET that cuts a Word or PowerPoint file into smaller files along page boundaries, so each piece fits the page or upload limit of a retrieval-augmented generation (RAG) pipeline or an AI tool. A pipeline that accepts four pages per file cannot take a 15-page catalogue as it is, and a deck of six slides will not pass a limit of two. GroupDocs.Merger for .NET offers three ways to get under such a limit, and this guide compares them: a page budget, one file per page, and an extract of chosen pages. Each result is an ordinary DOCX or PPTX file in the format you started with. Each method is judged by how it picks pages, what it writes to disk and which situation it fits. The console output and file names below come from a licensed run of the sample on GroupDocs.Merger 26.11.0. ## What This Guide Covers The guide compares `SplitIntoPageBudget`, `SplitIntoSinglePages` and `ExtractPagesForQuestion`, three methods of the sample project, for developers who feed Word and PowerPoint documents to a RAG pipeline or an AI tool with page or upload limits. **Prerequisites:** - .NET 8 SDK or later and GroupDocs.Merger for .NET 26.11 - A Word or PowerPoint file longer than your page budget; the sample uses a 15-page catalogue, a 10-page handbook and a 6-slide deck {{< alert style="warning" >}} ⚠️ Without a licence the library runs in evaluation mode and evaluation limits apply: it reads only the first pages. Get a [temporary licence](https://purchase.groupdocs.com/temporary-license) before you judge chunk counts. {{< /alert >}} ## Installation ```bash dotnet add package GroupDocs.Merger --version 26.11.0 ``` The package is also listed on [NuGet.org](https://www.nuget.org/packages/GroupDocs.Merger/). ## Repository Structure ``` split-documents-into-page-chunks-for-rag-dotnet/ ├── PageChunksForRag.csproj ├── Program.cs └── resources/ ├── deck.pptx ├── handbook.docx └── parts-catalogue.docx ``` `Program.cs` holds the three methods: [SplitIntoPageBudget, lines 78-108](https://github.com/groupdocs-merger/split-documents-into-page-chunks-for-rag-dotnet/blob/main/Program.cs#L78-L108), [SplitIntoSinglePages, lines 110-127](https://github.com/groupdocs-merger/split-documents-into-page-chunks-for-rag-dotnet/blob/main/Program.cs#L110-L127) and [ExtractPagesForQuestion, lines 129-148](https://github.com/groupdocs-merger/split-documents-into-page-chunks-for-rag-dotnet/blob/main/Program.cs#L129-L148). ## Quick Decision Matrix | Your limit or need | Recommended method | Why | |---|---|---| | A service accepts N pages per upload | Page budget | A few larger files, each within N pages | | Answers must cite one page and open it | One file per page | Every page is its own file | | Retrieval already knows the relevant pages | Extract | The model gets only those pages | | A document already fits the limit | Page budget | It is saved whole as a single chunk | ## Method Comparison Overview | Method | Pages chosen by | Files written | Best for | |---|---|---|---| | **SplitIntoPageBudget** | Chunk starts, `SplitMode.Interval` | One per chunk | Batch ingestion under a page cap | | **SplitIntoSinglePages** | Every page listed, `SplitMode.Pages` | One per page | Page-level retrieval | | **ExtractPagesForQuestion** | Chosen pages, `ExtractOptions` | One | One focused question | ## Detailed Method Analysis ### Method 1: Page Budget (SplitIntoPageBudget) **Overview:** a limit expressed in pages becomes a list of chunk starts, and one `Split` call writes the chunks. #### How It Works `GetDocumentInfo` reports the page count, the sample derives the first page of every chunk after the first, and `SplitOptions` receives them with `SplitMode.Interval`. When the document already fits, the list is empty and the sample saves the whole file as chunk 0. #### When to Use - ✅ A service caps pages per upload - ✅ Long files arrive in batches - ❌ Not for page-by-page citation; use Method 2 #### Implementation ```csharp string sourcePath = "resources/parts-catalogue.docx"; string outputPattern = "output/catalogue-chunk_{0}.{1}"; int maxPages = 4; Directory.CreateDirectory("output"); using var merger = new Merger(sourcePath); var info = merger.GetDocumentInfo(); ``` ```csharp int[] chunkStarts = Enumerable.Range(1, (info.PageCount - 1) / maxPages) .Select(chunk => chunk * maxPages + 1) .ToArray(); merger.Split(new SplitOptions(outputPattern, chunkStarts, SplitMode.Interval)); ``` #### Pros and Cons **Advantages:** - Few files, each within the budget - The budget is the only number you set **Limitations:** - A chunk cannot be cited by page without extra bookkeeping The catalogue reported 15 pages and starts 5, 9 and 13, and wrote four chunks of 4, 4, 4 and 3 pages. The 6-slide deck with a budget of 2 started chunks at 3 and 5 and wrote three PPTX files of 2 slides each. In our run every one of the 420 catalogue rows landed in exactly one chunk, in order, and each of the three later chunks opened with the repeated table header row. ### Method 2: One File per Page (SplitIntoSinglePages) **Overview:** every page number goes into the list, so each page becomes its own file. #### How It Works `SplitOptions` without a mode uses `SplitMode.Pages`, which writes one file for each listed page. The list is built from `PageCount`, so no page number is typed by hand. #### When to Use - ✅ Retrieval returns single pages - ✅ A citation should name a page and open it - ❌ Not when many small files are a problem for your storage #### Implementation ```csharp string sourcePath = "resources/handbook.docx"; string outputPattern = "output/handbook-page_{0}.{1}"; Directory.CreateDirectory("output"); using var merger = new Merger(sourcePath); int pageCount = merger.GetDocumentInfo().PageCount; int[] everyPage = Enumerable.Range(1, pageCount).ToArray(); merger.Split(new SplitOptions(outputPattern, everyPage)); ``` #### Pros and Cons **Advantages:** - The finest granularity the API offers - Predictable file names **Limitations:** - File count equals page count The 10-page handbook produced 10 files, `handbook-page_1.docx` to `handbook-page_10.docx`. ### Method 3: Extract the Pages One Question Needs (ExtractPagesForQuestion) **Overview:** keep chosen pages in a new document and drop the rest, so the model receives a short, focused file. #### How It Works `ExtractPages` takes the page numbers from `ExtractOptions`, and `Save` writes the result in the source format, so a DOCX stays a DOCX. The sample then reopens the saved file and reads its page count as a check. #### When to Use - ✅ A retrieval step has already ranked the pages - ✅ The same long document answers many questions - ❌ Not for cutting a whole document into parts #### Implementation ```csharp string sourcePath = "resources/parts-catalogue.docx"; string outputPath = "output/catalogue-pages-6-7.docx"; Directory.CreateDirectory("output"); using (var merger = new Merger(sourcePath)) { merger.ExtractPages(new ExtractOptions(new[] { 6, 7 })); merger.Save(outputPath); } using var extract = new Merger(outputPath); Console.WriteLine($"pages in the extract: {extract.GetDocumentInfo().PageCount}"); ``` #### Pros and Cons **Advantages:** - Smallest input for the model - Works on any page list **Limitations:** - Needs the page numbers from somewhere else Pages 6 and 7 of the catalogue produced `catalogue-pages-6-7.docx`, and reopening it reported 2 pages. ## Side-by-Side Feature Comparison | Feature | Page budget | One file per page | Extract | |---|---|---|---| | Output unit | Chunk of several pages | Single page | Chosen pages | | Mode or option | `SplitMode.Interval` | `SplitMode.Pages` | `ExtractOptions` | | Short document | Saved whole as chunk 0 | One file per page | Chosen pages only | | Source format kept | Yes | Yes | Yes | ## Real-World Use Cases ### Use Case 1: A catalogue behind a page cap **Challenge:** a 15-page catalogue with 420 table rows exceeds a four-page limit. **Solution:** Method 1. **Result:** four chunks, with no row lost or repeated. ### Use Case 2: A deck behind a slide cap **Challenge:** a 6-slide deck exceeds a limit of two. **Solution:** Method 1 on a PPTX. **Result:** three files of 2 slides each. ### Use Case 3: A question about two pages **Challenge:** one answer needs only part of the catalogue. **Solution:** Method 3. **Result:** a 2-page document. ## Common Pitfalls and How to Avoid Them 1. **Expecting the same file names from both split modes.** - **Problem:** `SplitMode.Pages` names files by page number starting at 1, while `SplitMode.Interval` numbers chunks from 0. - **Solution:** build any lookup from the pattern you passed, not from a guess. 2. **Passing chunk lengths instead of chunk starts.** - **Problem:** `SplitMode.Interval` cuts at the numbers you list, so lengths cut in the wrong places. - **Solution:** derive the starts from `PageCount`, as the sample does. 3. **Judging results from an unlicensed run.** - **Problem:** evaluation limits apply and only the first pages are read. - **Solution:** apply a temporary licence before comparing chunk counts. ## Notes Page operations on Word documents follow the real Word page layout since GroupDocs.Merger 26.11; the [26.11 release notes](https://releases.groupdocs.com/merger/net/release-notes/2026/groupdocs-merger-for-net-26-11-release-notes/) describe the earlier behaviour. This guide makes no statement about token counts or about the limits of any particular AI product. ## How do I choose between page budgets and single pages? Choose a page budget when a service caps pages per upload and you want few, larger files. Choose single pages when retrieval should return one page at a time and cite its number. Both use `SplitOptions`; only the mode and the list of page numbers differ. If you need only a handful of known pages, skip splitting and call `ExtractPages`. ## FAQ **Can the same code cut a PowerPoint file?** Yes. `SplitIntoPageBudget` cut the 6-slide `deck.pptx` with the same calls as the Word catalogue. **What happens to a document shorter than the budget?** The list of chunk starts is empty, so the sample saves the whole document as one chunk with the extension taken from `info.Type`. **Do the chunks stay in the original format?** Yes. GroupDocs.Merger reads and writes DOCX and PPTX in their own format, so a catalogue chunk is a DOCX and a deck chunk is a PPTX. ## Conclusion Pick the method by the limit you face: a page budget for a cap per upload, single pages for page-level citation, an extract for one question. All three use `GetDocumentInfo`, `Split` or `ExtractPages`, and all three keep the source format. Start from the [sample repository](https://github.com/groupdocs-merger/split-documents-into-page-chunks-for-rag-dotnet), swap in your own files and a licence, and compare the chunk counts with your limit. ## See Also - [In-depth blog article about this project](https://blog.groupdocs.com/merger/split-documents-into-page-chunks-for-rag-net/) - the page-chunk workflow step by step - [Split a document with GroupDocs.Merger for .NET](https://docs.groupdocs.com/merger/net/split-document/) - split options and modes in the documentation - [Extract pages with GroupDocs.Merger for .NET](https://docs.groupdocs.com/merger/net/extract-pages/) - keep selected pages of a document - [GroupDocs.Merger for .NET documentation](https://docs.groupdocs.com/merger/net/) - getting started and advanced topics - [GroupDocs.Merger for .NET API reference](https://reference.groupdocs.com/merger/net/) - full API details - [GroupDocs.Merger 26.11 release notes](https://releases.groupdocs.com/merger/net/release-notes/2026/groupdocs-merger-for-net-26-11-release-notes/) - [GroupDocs.Merger on NuGet.org](https://www.nuget.org/packages/GroupDocs.Merger/) - [Full working example on GitHub](https://github.com/groupdocs-merger/split-documents-into-page-chunks-for-rag-dotnet)