---
title: "Merging PDFs | Nutrient Java SDK"
canonical_url: "https://www.nutrient.io/guides/java/editor/merge-pdf-into-other-pdf/"
md_url: "https://www.nutrient.io/guides/java/editor/merge-pdf-into-other-pdf.md"
last_updated: "2026-06-09T10:32:42.836Z"
description: "Merging PDFs using Nutrient Java SDK."
---

# Merging PDFs

Use document merging to combine multiple files into one PDF.

Common use cases include:

- Consolidating reports into one deliverable

- Combining scanned and digital documents

- Building document packages for distribution

- Merging mixed formats into a single PDF output

[Download sample](https://www.nutrient.io/downloads/samples/java/merge-pdf-into-other-pdf.zip)

## How Nutrient helps

Nutrient Java SDK handles document appending and export.

The SDK enables you to:

- Open documents from file paths or streams

- Append one document into another

- Export the final merged document as PDF

## Preparing the project

Start by specifying a package name and importing the required classes:

```java

package io.nutrient.Sample;

import io.nutrient.sdk.*;
import io.nutrient.sdk.exceptions.NutrientException;
import io.nutrient.sdk.editors.*;
import io.nutrient.sdk.exporters.*;

```

Create the main method and declare `NutrientException` for this sample:

```java

public class PDFMerging {
    public static void main(String[] args) throws NutrientException {

```

## Merging multiple documents

Open the base document with try-with-resources.

In this sample:

- The base input is `input.docx`.

- File paths are used.

- Streams are also supported.

```java

        try (Document document = Document.open("input.docx")) {

```

Create a `PdfEditor` instance for merge operations:

```java

            PdfEditor editor = PdfEditor.edit(document);

```

## Appending additional documents

Open another document and append it to the base document.

In this sample, a PDF (`input.pdf`) is appended to the Word-based document. The SDK handles format conversion automatically, so `appendDocument()` can merge PDF with other supported input formats, including Word (`.docx`, `.doc`), Excel (`.xlsx`, `.xls`), PowerPoint (`.pptx`, `.ppt`), and additional supported document types (for example, `.rtf`, `.odt`, `.txt`, `.md`, `.html`, `.mhtml`).

If the appended document isn’t already a PDF, the SDK converts it to PDF before appending (with implicit conversion enabled by default).

```java

            try (Document document2 = Document.open("input.pdf")) {
                editor.appendDocument(document2);
            }

```

## Saving the merged result

Save editor changes and export the merged result as PDF:

```java

            editor.save();
            editor.close();

            document.export("output_merged_documents.pdf", new PdfExporter());
        }
    }
}

```

## Error handling

The sample throws `NutrientException` for SDK and processing issues.

In production code:

- Catch `NutrientException`.

- Return a clear error message.

- Log failure details for debugging.

## Conclusion

Use this workflow to merge documents into one PDF:

1. Open the base document.

2. Create a `PdfEditor`.

3. Open each additional document and append it.

4. Save editor changes.

5. Export the merged output with `PdfExporter`.

> Available input formats can depend on your license/features (for example, Office, HTML, or image conversion capabilities).

For related document workflows, refer to the [Java SDK guides](https://www.nutrient.io/guides/java.md).

Download [this ready-to-use sample package](https://www.nutrient.io/downloads/samples/java/merge-pdf-into-other-pdf.zip).
---

## Related pages

- [Adding annotations to a PDF document](/guides/java/editor/add-annotations-to-pdf.md)
- [Adding interactive form fields to a PDF document](/guides/java/editor/add-form-fields-to-pdf.md)
- [Adding free text annotations to a PDF document](/guides/java/editor/add-freetext-annotations-to-pdf.md)
- [Adding a custom page to a PDF document](/guides/java/editor/add-custom-page-to-pdf.md)
- [Adding invisible digital signatures to a PDF document](/guides/java/editor/add-invisible-signature-to-pdf.md)
- [Adding link annotations to a PDF document](/guides/java/editor/add-link-annotations-to-pdf.md)
- [Adding redaction annotations to a PDF document](/guides/java/editor/add-redaction-annotations-to-pdf.md)
- [Adding stamp annotations to a PDF document](/guides/java/editor/add-stamp-annotations-to-pdf.md)
- [Adding sticky note annotations to a PDF document](/guides/java/editor/add-sticky-note-annotations-to-pdf.md)
- [Adding shape annotations to a PDF document](/guides/java/editor/add-shape-annotations-to-pdf.md)
- [Adding text markup annotations to a PDF document](/guides/java/editor/add-text-markup-annotations-to-pdf.md)
- [Adding visible digital signatures to a PDF document](/guides/java/editor/add-visible-signature-to-pdf.md)
- [Advanced digital signature workflows](/guides/java/editor/advanced-digital-signatures.md)
- [Detecting and adding form fields to a PDF document](/guides/java/editor/detect-and-add-form-fields.md)
- [Editing PDF form fields](/guides/java/editor/editing-pdf-form-fields.md)
- [Nutrient Java SDK editor guides](/guides/java/editor.md)
- [Editing PDF metadata with Nutrient Java SDK](/guides/java/editor/editing-pdf-metadata.md)
- [Filling PDF form fields](/guides/java/editor/fill-pdf-form.md)
- [Managing PDF page order](/guides/java/editor/manage-pdf-page-order.md)

