---
title: "Merging PDFs | Nutrient Python SDK"
canonical_url: "https://www.nutrient.io/guides/python/editor/merge-pdf-into-other-pdf/"
md_url: "https://www.nutrient.io/guides/python/editor/merge-pdf-into-other-pdf.md"
last_updated: "2026-05-26T01:23:09.689Z"
description: "Merging PDFs using Nutrient Python SDK."
---

# Merging PDFs

Merging multiple documents into a single PDF — whether consolidating reports, combining scanned pages with digital documents, or assembling documentation packages — is a fundamental requirement for document management systems.

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

## How Nutrient helps you achieve this

Nutrient Python SDK handles document merging and format conversion. With the SDK, you don’t need to worry about:

- Parsing document internals

- Managing page structures across formats

- Handling format conversion

- Complex document assembly logic

Instead, Nutrient provides an API that handles all the complexity behind the scenes, letting you focus on your business logic.

## Complete implementation

Below is a complete working example that demonstrates merging documents into a single PDF. These lines set up the Python application. The import statements bring in all necessary classes from the Nutrient SDK:

```python

from nutrient_sdk import Document
from nutrient_sdk import PdfEditor
from nutrient_sdk import PdfExporter
from nutrient_sdk import NutrientException

```

This line opens the Word document that will serve as the base for your merged PDF. The [context manager](https://docs.python.org/3/reference/datamodel.html#context-managers) syntax ensures the document is automatically closed when you’re done, preventing resource leaks:

```python

def main():
    try:
        with Document.open("input.docx") as document:

```

Here, you create a `PdfEditor` instance that will enable you to manipulate the document. This editor provides all the methods needed for document merging:

```python

            editor = PdfEditor.edit(document)

```

This block opens a second document and appends it to the base document. The SDK handles format conversion automatically, so `append_document()` 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):

```python

            with Document.open("input.pdf") as document2:
                editor.append_document(document2)

```

This block saves the changes, closes the editor, and exports the merged result as a PDF. The try-except block handles potential errors using `NutrientException`:

```python

            editor.save()
            editor.close()

            document.export("output_merged_documents.pdf", PdfExporter())
            print("Successfully merged documents")
    except NutrientException as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

```

## Conclusion

The document merging logic consists of four steps:

1. Open the base document.

2. Create an editor.

3. Append additional documents.

4. Save and export as PDF.

Nutrient handles format conversion and document assembly so you don’t need to understand document internals or manage page structures manually.

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

You can download [this ready-to-use sample package](https://www.nutrient.io/downloads/samples/python/merge-pdf-into-other-pdf.zip) that’s fully configured to help you get started with the Python SDK.
---

## Related pages

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

