Skip to content

Instantly share code, notes, and snippets.

Split single document to multiple resultant documents in C# .NET
// Supports merging Microsft Word, Excel, PowerPoint, Visio, OpenDocument, HTML, eBook and PostScript file formats
// Supported file formats: https://docs.groupdocs.com/merger/net/supported-document-formats/
using (Watermarker watermarker = new Watermarker("input.pdf"))
{
Font font = new Font("Arial", 19, FontStyle.Bold | FontStyle.Italic);
TextWatermark watermark = new TextWatermark("my watermark", font);
watermark.ForegroundColor = Color.Red;
watermark.BackgroundColor = Color.Blue;
watermark.TextAlignment = TextAlignment.Right;
watermark.Opacity = 0.5;
watermarker.Add(watermark);
watermarker.Save("output.pdf");
}
string outputFolder = @"c:\output\";
SplitOptions splitOptions = new SplitOptions(outputFolder + "document_{0}.{1}", new int[] { 1, 2, 4 });
using (Merger merger = new Merger("output.pdf"))
{
merger.Split(splitOptions);
}

Split One Document to Many Documents in .NET

The below C# code example demonstrates how to split a single document to multiple individual documents and add text or image watermarks to each of the splitted document in C# .NET using GroupDocs.Merger and GroupDocs.Watermark APIs.

View a list of all supported document formats here.

APIs to Use

Installation

Download GroupDocs.Watermark & GroupDocs.Merger assemblies from https://releases.conholdate.com/total/net/ or install the whole package directly from Nuget https://www.nuget.org/packages/Conholdate.Total/ into your workplace.

More About .NET Documents Splitter API

Home | Product Page | Docs | New Releases | API Reference | Examples | Blog | Free Support | Temporary License | About Us

// Supports merging Microsft Word, Excel, PowerPoint, Visio, OpenDocument, HTML, eBook and PostScript file formats
// Supported file formats: https://docs.groupdocs.com/merger/net/supported-document-formats/
string filePath = @"c:\sample.txt";
string filePathOut = @"c:\output\line_{0}.{1}";
TextSplitOptions splitOptions = new TextSplitOptions(filePathOut, new int[] { 3, 6 });
using (Merger merger = new Merger(filePath))
{
merger.Split(splitOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment