When we talk about joining or merging documents, we are referring to the process of combining two or more documents into a single file. There are several reasons why you might want to do this, such as making it easier to share information or to create a single, consolidated document. Another purpose of merging documents could be to create a unified file that contains all the information from multiple documents. For instance, you might want to create one centralized file that contains all the text from a document, all the images from a second document, and all the data from a third document.
Just like merging a file, in some cases, you may also need to split a document to create multiple documents. Splitting a file can be very useful when you need to create separate reports or presentations that contain different data sets. Or if you need to send a large document to someone but don’t want them to have to download a huge file. If you are looking for a platform-independent solution to programmatically merge or split data files, GroupDocs.Merger APIs for .NET and Java could be your ultimate choice. These APIs empower .NET and Java developers to split or join PDF, Word, Excel, and PowerPoint documents, diagrams, and eBooks, as well as merge JPG, PNG, GIF, and TIFF images in their file merger apps.
To start merging documents and images or splitting them, please install the required version of GroupDocs.Merger (for .NET or Java) and all prerequisites to enjoy a seamless experience.
Please download the MSI installer or DLLs from the download section, install the API via NuGet, or use the Package Manager Console to install GroupDocs.Merger for .NET:
For more help and information, please view the detailed installation guide.
For installing the Java version of GroupDocs.Merger API, you can either download the JAR file directly or use the latest configurations in your Maven applications in Java.
<repository> <id>groupdocs-artifacts-repository</id> <name>GroupDocs Artifacts Repository</name> <url>https://releases.groupdocs.com/java/repo/</url> </repository> <dependency> <groupId>com.groupdocs</groupId> <artifactId>groupdocs-merger</artifactId> <version>22.7</version> </dependency>
Please view this guide for further help on installing GroupDocs.Merger for Java.
Upon successfully setting up GroupDocs.Merger for .NET or Java on your system, you can check some of the popular use cases for joining or splitting documents, and swapping, rotating, extracting, or deleting document pages.
PDF files have become the standard for document sharing and storage, and we often need to merge PDF files for various reasons such as combining data from multiple PDF documents into one file for peer review. Or, to centralize the resources like graphs and tables contained within the documents found on the company intranet for easy reference. Whatever the case scenario may be, GroupDocs.Merger APIs for .NET and Java are loaded with the right tool sets for you to combine PDF files while also preserving the text and graphical contents of the source documents.
It will only take a few lines of C# code to combine PDFs into one file as shown in the below sample:
// Load the source PDF document using (Merger merger = new Merger(@"c:\sample1.pdf")) { // Add a PDF file to merge merger.Join(@"c:\sample2.pdf"); // Merge both PDF files and save the result merger.Save(@"c:\merged.pdf"); }
Along with merging PDF files, you also have the option to merge multiple files of DOC, PPT, and XLS formats into a PDF document. Please use the following C# code for this purpose:
Joining more than one PDF files into a single document is simple in Java too as shown in the code below:
// Load the source PDF document Merger merger = new Merger("c:\sample1.pdf") // Add another PDF document merger.join("c:\sample2.pdf"); // Merge both PDF files and save the result merger.save("c:\merged.pdf");
Versatility and ease of use are two of the factors that make Microsoft Word, Excel, and PowerPoint so popular the world over. These software applications allow us to create different types of professional-looking documents easily. Word is great for creating text-based documents, Excel is perfect for storing and manipulating data, and PowerPoint is ideal for creating presentations. You can merge any of these file types using GroupDocs.Merger APIs for .NET and Java.
You can combine your Word documents using the C# code shown below. It must also be noted that this code is generic and could be used to merge Excel and PowerPoint files too. The only difference will be replacing the document name and type. For example, ‘sample1.docx’, ‘sample2.docx’, and ‘merged.docx’ will have the document extension changed from DOCX to either XLSX or PPTX.
// Load the source DOCX file using (Merger merger = new Merger(@"c:\sample1.docx")) { // Add another DOCX file to merge merger.Join(@"c:\sample2.docx"); // Merge DOCX files and save the result merger.Save(@"c:\merged.docx"); }
Another very useful feature of GroupDocs.Meger for .NET API is to combine pages from different files into one document based on the specified page number or ranges. The following C# code lets you achieve this:
string filePath = @"c:\sample1.docx"; string filePath2 = @"c:\sample2.docx"; string filePathOut = @"c:\output\result.docx"; JoinOptions joinOptions = new JoinOptions(1, 4, RangeMode.OddPages); using (Merger merger = new Merger(filePath, loadOptions)) { merger.Join(filePath2, joinOptions); merger.Save(filePathOut); }
Merging documents of other popular formats such as ODT, EPUB, TXT, TEX, and HTML is also supported. Please check this guide for more help.
Just like in .NET, Java users can also combine their Word documents easily using the below-given sample code. This same code snippet could be used to merge Excel and PowerPoint documents as well. You will only need to replace the file names and extensions when working with spreadsheets and presentation files. As in, please replace DOCX extension with XLSX or PPTX in this code.
// Load the source DOCX file Merger merger = new Merger("c:\sample1.docx") // Add another DOCX file to merge merger.join("c:\sample2.docx"); // Merge DOCX files and save the result merger.save("c:\merged.docx");
GroupDocs.Merger for Java lets you merge pages of several documents into a single file. You can specify the pages you want to combine in the resulting document. Please use the below-given sample Java code for this purpose:
String filePath = "c:\sample.docx"; String filePath2 = "c:\sample2.docx"; String filePathOut = "c:\output\result.docx"; // Set the start and end page numbers in JoinOptions class. JoinOptions joinOptions = new JoinOptions(1, 2); // Merge selective pages using the join method Merger merger = new Merger(filePath); merger.join(filePath2 , joinOptions); merger.save(filePathOut);
For more information on merging files of other formats including OpenDocument, EPUB, TEX, TXT, and HTML in Java, please visit this guide.
Merging or joining different raster image files such as PNG, JPG, TIFF, and others can be a good way to create unique visuals for various purposes. Merging images may also be used to combine multiple images into one larger image, create a photomontage, remove unwanted elements from an image, or even create a collage. If you are someone who works with images regularly, you can use GroupDocs.Merger APIs for merging raster images such as JPG, PNG, TIFF, and GIF.
To combine JPG image files, please utilize the C# coding shown below. You can merge JPG images horizontally or vertically depending on your intended use:
// Load the source image file using (Merger merger = new Merger(@"c:\sample1.jpg")) { // Define image join options with horizontal join mode ImageJoinOptions joinOptions = new ImageJoinOptions(ImageJoinMode.Horizontal); // Add another image file to merge merger.Join(@"c:\sample2.jpg", joinOptions); // Define image join options with vertical join mode joinOptions = new ImageJoinOptions(ImageJoinMode.Vertical); // Add the next image file to merge merger.Join(@"c:\sample3.jpg", joinOptions); // Merge image files and save the result merger.Save(@"c:\merged.jpg"); }
Similarly, you can combine PNG, GIF, and other image file formats in .NET.
Please use the Java code snippet shared below for merging JPG image files. You have the option to merge images vertically or horizontally:
// Load the source image file Merger merger = new Merger("c:\sample1.jpg") // Define image join options with horizontal join mode ImageJoinOptions joinOptions = new ImageJoinOptions(ImageJoinMode.Horizontal); // Add another image file to merge merger.join("c:\sample2.jpg", joinOptions); // Define image join options with vertical join mode joinOptions = new ImageJoinOptions(ImageJoinMode.Vertical); // Add the next image file to merge merger.join("c:\sample3.jpg", joinOptions); // Merge image files and save the result merger.save("c:\merged.jpg");
Along with JPG, you can also combine PNG and BMP images in Java.
Document splitting is the process of breaking down a single file into multiple smaller documents. Some practical uses of file splitting can be organizing related documents in separate files, simplifying the process of sharing and collaborating, facilitating easier editing, and allowing for more efficient searching and retrieval of information. GroupDocs.Merger APIs provide you with all the necessary tools required to seamlessly split documents of different formats in .NET and Java.
You can split your PDF, DOCX, XLSX, PPTX, and other data files in .NET based on various split options such as by exact page numbers, by starting and ending pages, with even/odd filters, and more. The following C# code lets you split a PDF document by specified page numbers. This will generate three separate documents containing one page each as defined in SplitOptions:
string filePath = @"c:\sample.pdf"; string filePathOut = @"c:\output\document_{0}.{1}"; // Define page numbers in SplitOptions SplitOptions splitOptions = new SplitOptions(filePathOut, new int[] { 3, 6, 8 }); // Split the document based on the specified split options using (Merger merger = new Merger(filePath)) { merger.Split(splitOptions); }
You can similarly split your DOCX, XLSX, PPTX, and other documents using GroupDocs.Merger for .NET.
The same options for splitting data files are available in Java too. You can make use of these options when splitting PDF files, Word, Excel, and PowerPoint documents like defining page numbers, specifying page ranges, and more. In the below-shared example, we will be using specific page numbers to split a PDF file into three, separate single paged documents:
String filePath = "document.pdf"; String filePathOut = "document\_{0}.{1}"; // Specify page numbers and split the file into multiple single-page documents. SplitOptions splitOptions = new SplitOptions(filePathOut, new int\[\] { 3, 6, 8 }); Merger merger = new Merger(filePath); merger.split(splitOptions);
Feel free to split your Word, Excel, PowerPoint, and other documents in Java in the same manner.
Together with merging or splitting your data files, you can also perform several other file operations such as extracting, rotating, swapping, and removing document pages with the help of GroupDocs.Merger APIs. All these functionalities are supported in both the .NET and Java versions of GroupDocs.Merger. So, let’s check out some of these features and how they work.
Please use the following C# code to extract specific pages from a source PDF document:
string filePath = @"c:\sample.pdf"; string filePathOut = @"c:\output\result.pdf"; // Resultant document will contain pages 1 and 4 ExtractOptions extractOptions = new ExtractOptions(new int[] { 1, 4 }); using (Merger merger = new Merger(filePath)) { merger.ExtractPages(extractOptions); merger.Save(filePathOut); }
And to rotate specific pages of a PDF document by 90, 180, or 270 degrees, please use this C# code. For checking other supported document operations, please visit this page:
To swap one document page with another, please use the Java code shown below:
String filePath = "c:\sample.pptx"; String filePathOut = "c:\output\result.pptx"; // Set page numbers to be swapped int pageNumber1 = 3; int pageNumber2 = 6; // Define swap options based on the selected page numbers SwapOptions swapOptions = new SwapOptions(pageNumber2, pageNumber1); Merger merger = new Merger(filePath); merger.swapPages(swapOptions); merger.save(filePathOut);
For removing one or more document pages, please use the following sample Java code. To review other supported file operations, please check the relevant page here:
String filePath = "c:\sample.one"; String filePathOut = "c:\output\result.one"; // Define the pages to be removed RemoveOptions removeOptions = new RemoveOptions(new int[] { 3, 5 }); // Process the page removal file operation Merger merger = new Merger(filePath); merger.removePages(removeOptions); merger.save(filePathOut);
We also provide Free Online Apps to merge or split PDF, DOCX, XLXS, PPTX, and EPUB files. Please be sure to try the free apps if you are looking to merge Word to PDF, Excel to PDF, PowerPoint to PDF, merge JPG, PNG, BMP, and many other data files.
You can easily export data to Microsoft Excel from various available sources such as JSON, and CSV.
Continue ReadingYou have several Excel workbooks, and you want to combine them together into one file for reporting or to keep data in one place
Continue ReadingConverting Word documents including DOC or DOCX in .NET is a very common requirement
Continue Reading