# Merge and split documents with GroupDocs.Merger Join documents, split them into single pages and read document information with GroupDocs.Total for Java, with runnable Java examples and downloadable input and output files. GroupDocs.Merger combines documents and rearranges their pages — join, split, extract, remove, reorder, rotate — and manages document passwords. It works on Word, PDF, spreadsheets, presentations, images and archives. Every example below opens `contract.docx` and is ready to copy into a project once you have [installed the package]({{< ref "/total/java/getting-started/installation.md" >}}). ## Join two documents `join` appends another document to the one you opened. Call it repeatedly to combine several, then `save` the result. {{< tabs "merger-join-documents" >}} {{< tab "Java" >}} ```java import com.groupdocs.merger.Merger; Merger merger = new Merger("contract.docx"); merger.join("statement-of-work.docx"); // Merger.save resolves a bare relative name oddly, so pass an absolute path merger.save(new java.io.File("merger-join-documents.docx").getAbsolutePath()); ``` {{< /tab >}} {{< tab "Sample files" >}} {{< tab-text >}} `contract.docx` and `statement-of-work.docx` are the sample files used in this example. Download [contract.docx](https://docs.groupdocs.com/total/java/_sample_files/contract.docx) and [statement-of-work.docx](https://docs.groupdocs.com/total/java/_sample_files/statement-of-work.docx). {{< /tab-text >}} {{< /tab >}} {{< tab "merger-join-documents.docx" >}} ```text Binary file (DOCX, 15 KB) ``` [Download full output](https://docs.groupdocs.com/total/java/_output_files/developer-guide/merger/MergerJoinDocuments/merger-join-documents.docx) {{< /tab >}} {{< /tabs >}} ## Split a document into pages `split` breaks one document into several. With `SplitMode.Pages` and a list of page numbers, each listed page is written out as its own file — here both pages of the contract land separately in the `merger-split-pages` folder. {{< tabs "merger-split-pages" >}} {{< tab "Java" >}} ```java import com.groupdocs.merger.Merger; import com.groupdocs.merger.domain.options.SplitMode; import com.groupdocs.merger.domain.options.SplitOptions; Merger merger = new Merger("contract.docx"); // {0} is replaced with the page number, so page 1 becomes page_1.docx. // contract.docx has two pages. int[] pageNumbers = new int[] { 1, 2 }; SplitOptions splitOptions = new SplitOptions( "merger-split-pages/page_{0}.docx", pageNumbers, SplitMode.Pages); merger.split(splitOptions); ``` {{< /tab >}} {{< tab "contract.docx" >}} {{< tab-text >}} `contract.docx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/total/java/_sample_files/contract.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "merger-split-pages.zip" >}} ```text merger-split-pages/page_1.docx (24 KB) merger-split-pages/page_2.docx (20 KB) ``` [Download full output](https://docs.groupdocs.com/total/java/_output_files/developer-guide/merger/MergerSplitPages/merger-split-pages.zip) {{< /tab >}} {{< /tabs >}} ## Read document information `getDocumentInfo` reports the format, page count and size — worth checking before you split a document into pages that may not exist. {{< tabs "merger-document-info" >}} {{< tab "Java" >}} ```java import com.groupdocs.merger.Merger; import com.groupdocs.merger.domain.result.IDocumentInfo; Merger merger = new Merger("contract.docx"); IDocumentInfo info = merger.getDocumentInfo(); System.out.println("File type: " + info.getType().getFileFormat()); System.out.println("Pages: " + info.getPageCount()); System.out.println("Size: " + info.getSize() + " bytes"); ``` {{< /tab >}} {{< tab "contract.docx" >}} {{< tab-text >}} `contract.docx` is the sample file used in this example. Click [here](https://docs.groupdocs.com/total/java/_sample_files/contract.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "merger-document-info.txt" >}} ```text File type: Microsoft Word Open XML Document Pages: 3 Size: 15096 bytes ``` [Download full output](https://docs.groupdocs.com/total/java/_output_files/developer-guide/merger/MergerDocumentInfo/merger-document-info.txt) {{< /tab >}} {{< /tabs >}} ## Learn more GroupDocs.Merger also removes, moves, swaps and rotates pages, changes page orientation, adds, updates and removes document passwords, generates page previews, and offers a page builder for chaining operations. * [GroupDocs.Merger for Java documentation](https://docs.groupdocs.com/merger/java/) — the full product guide * [Supported file formats](https://docs.groupdocs.com/merger/java/supported-document-formats/) * [API reference](https://reference.groupdocs.com/merger/java/)