Nutrient Python SDK

Merge, split, and edit PDFs in Python

  • Merge PDF files and other document formats into a single PDF
  • Split PDFs by removing pages or extracting specific page ranges
  • Reorder, insert, and swap pages with a simple page collection API
  • The SDK handles document internals, page structures, and format conversion

Need pricing or implementation help? Talk to Sales.

PDF EDITING IN PYTHON

from nutrient_sdk import Document
from nutrient_sdk import PdfEditor
from nutrient_sdk import PdfExporter
from nutrient_sdk import NutrientException
def main():
try:
with Document.open("input.docx") as document:
editor = PdfEditor.edit(document)
with Document.open("input.pdf") as document2:
editor.append_document(document2)
editor.save()
editor.close()
document.export("merged.pdf", PdfExporter())
print("Successfully merged documents")
except NutrientException as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()

USE CASES

When developers reach for this SDK

Combine PDF files in automated pipelines

Reports, invoices, and scanned pages arrive separately. Merge PDF files into a single document in a Django view, FastAPI endpoint, or background task.

Split PDFs for distribution

Extract specific pages or remove sections from large documents. Split a PDF into smaller files for targeted delivery or archiving.

Assemble documents from mixed formats

The SDK handles format conversion automatically — merge a Word document with a PDF and export the result as a single PDF.

Reorganize pages before publishing

Swap, move, and reorder pages programmatically. Build page-level editing into document management systems without manual PDF manipulation.

Edit PDFs in Python

Merge PDF files

Combine PDF files and other documents into a single PDF in Python. The SDK handles document assembly and format conversion.


  • Append documents with a single method call
  • Merge across formats — PDF with DOCX and more
  • SDK manages page structures and document internals

Split PDFs

Split a PDF by removing pages or keeping only the pages you need. Use the page collection API to control document structure.


  • Remove pages by index
  • Iterate pages to select which to keep
  • Save the result as a new PDF file

Reorder and manage pages

Swap, move, insert, and add pages to PDFs, with full programmatic control over page order and document structure.


  • Swap and move pages by index
  • Insert blank pages with custom dimensions
  • Add pages using predefined sizes like A4 or Letter


ADVANCED CAPABILITIES

Beyond basic PDF editing

The SDK handles more than one-off edits. Build PDF manipulation into automated workflows and deploy anywhere Python runs.

Illustration of PDF pages being merged, split, and reordered
Merge across formats

Combine PDFs with Word documents — the SDK handles format conversion automatically when you append documents.


Batch page operations

Iterate through pages in a loop to process, split, or reorganize multiple documents in a single script.


Server-side processing

No GUI dependencies — merge, split, and edit PDFs in background jobs, cron tasks, or API handlers.


Cross-platform deployment

Deploy anywhere Python runs — the SDK has no platform-specific system dependencies.


Frequently asked questions

How do I merge PDFs in Python?

Open the base document with Document.open(), create a PdfEditor, and then call editor.append_document() with each additional document. Save and export the result as a single PDF. The SDK handles page structures and document internals automatically. See the merge PDFs guide for a complete working example.

How do I combine PDF files from different formats?

The SDK handles format conversion automatically. You can open a Word document as the base, append a PDF to it, and export the merged result as a single PDF. Use Document.open() for each file — the SDK manages format differences internally.

How do I split a PDF in Python?

Open the PDF, create a PdfEditor, and use the page collection API to remove pages you don’t need with pages.remove_at(index). Then save the result as a new file. To extract specific pages, iterate through the collection and keep only the pages you want.

How do I merge PDF files in Python without external tools?

Install the Nutrient Python SDK and use PdfEditor with append_document() to combine files. The SDK is a standalone Python library — no external tools, system dependencies, or command-line utilities are required.

Can I reorder pages in a PDF with Python?

Yes. The page collection API provides swap(index1, index2) to exchange two pages and move_to(from, to) to relocate a page. You can also insert blank pages at specific positions with custom dimensions or predefined sizes like A4.

How do I edit a PDF in Python programmatically?

Use Document.open() to load the PDF and PdfEditor.edit() to create an editor. From there, you can merge documents, split pages, reorder content, and manage document structure. All changes are saved with editor.save_as().

Can I combine multiple PDF files into one in Python?

Yes. Open the first file as the base document, and then call editor.append_document() for each additional file. The SDK appends all pages from each document in order. Export the final result with document.export() using PdfExporter.

How do I handle errors when merging or splitting PDFs?

Wrap your code in a try-except block and catch NutrientException for SDK-specific errors. Use the context manager syntax (with Document.open(...) as document:) to ensure automatic resource cleanup even when errors occur.


FREE TRIAL

Ready to get started?

Start merging, splitting, and editing PDFs in Python in minutes — no payment information required.