Split or Merge PDF, Word, Excel Documents in C# or Java

Worried about merge or split documents of various types in multiple platforms? There could be many statements in your mind:

  • How to merge PDF documents together in Java?
  • Want to split word documents, or merge excel spreadsheets in CSharp.
  • What to do if I need to merge PPT/PPTX presentations.
  • Many more questions, the list may not end.
Split or Merge PDF, Word, Excel documents in Java

GroupDocs provides a document merging solution for all such requirements. GroupDocs.Merger allows you to merge documents and manipulate document structure across a wide range of supported document formats. It further allows manipulating document pages, page transformations, information extraction from the documents, generating previews and much more. The merger solution is not confined to native APIs, so it includes;

Merge with GroupDocs.Merger On-Premise APIs

In this article, we will only look a bit about the native APIs of GroupDocs.Merger which are currently available for .NET & Java.

Merge PDF in Java

GroupDocs.Merger for Java

GroupDocs.Merger is a simple way to merge two or more documents of the same format. Below is the code snippet from the examples, that is self-explanatory and needs no further clarification, hence shows how to merge PDF documents using the Java API.

Steps are simple if you have decided the documents to combine together:

  • Instantiate Merger object, having the first document with which other documents to be merged.
  • Call join method, passing the document to merge. Recall join method to merge more documents.
  • Call save method to save the final output.
  • That’s it.
// Set paths for the documents to join together in a single file.
String filePath1 = "document-1.pdf";
String filePath2 = "document-2.pdf";
String filePath3 = "document-3.pdf";
// Create Merger object containing the first document to be merged with other documents of the same format.
Merger merger = new Merger(filePath1 );
// Join Documents.
merger.join(filePath2 );
merger.join(filePath3 );
// Save the merged document.
String filePathOutput = "mergedDocument.pdf";

Merge Excel, Word, PowerPoint & Other Documents in Java

Merger API is not about just merge PDF documents, there is a large list of supported document file formats that can be merged using the document merger API. Your requirement could be any; merge word processing formats like DOC/DOCX, merge XLS/XLSX Excel spreadsheets, PPT/PPTX presentations, Visio Drawings, Web formats, Page Description Language formats, or eBooks. GroupDocs.Merger supports your format. Here is the list of supported file formats. Visit docs of GroupDocs to stay updated.

Document TypeFile Formats
PresentationsPPT, PPTX, PPS, PPSX, ODP, OTP
Page Description LanguagesTEX, XPS
eBooks & OthersPDF, EPUB, ONE

Merge Document Pages in C#

GroupDocs.Merger for .NET

The Merger API allows multiple documents to get merged with selective pages and also by specifying the desired page range. Your code will remain similar to the mentioned above, just a little change while setting your JoinOptions.

Below is the source code snippet from the examples that shows how to merge documents by specifying certain pages using the GroupDocs.Merger for .NET API.

// Set paths for the documents to join together in a single file.
string filePath1 = @"document-1.docx";
string filePath2 = @"document-2.docx";
string filePathOutput = @"mergedDocument.docx";
// Create join options.
JoinOptions joinOptions = new JoinOptions(1, 4, RangeMode.OddPages);
// Join the second document and save.
using (Merger merger = new Merger(filePath1, loadOptions))
    merger.Join(filePath2, joinOptions);

GroupDocs.Merger is not limited to just merge documents. It supports a large list of features for the supported file formats. Here are some of the features to get an idea about the APIs:

Split PDF, Excel, Word, and Other Documents into Multiple Documents

There are many ways in which your requirement could be, how to split a document.

  • Split by exact page numbers
  • Split by page range
  • Split by Even and Odd pages
  • Split a document to several multi-page documents

All of the above are offered by the GroupDocs.Merger API. Below code-example shows how to split a word document by providing the exact number of pages using the Java API:

String filePath = "document.docx";
String filePathOut = "document_{0}.{1}";
// Split the document into multiple single page documents.
PageSplitOptions splitOptions = new PageSplitOptions(filePathOut, new int[] { 3, 6, 8 });
Merger merger = new Merger(filePath);

Good to see you here, you can freely contact us on the forum in case you feel any difficulty or have some confusion or want to give some good suggestions.

Related Links