GroupDocs.Merger for Python via .NET lets you split a single source document into multiple output files. You can split by exact page numbers or by page intervals, and optionally filter to odd or even pages only — all controlled through SplitOptions.
Here are the steps to split a document:
Instantiate Merger with the path to the source document.
Create a SplitOptions object with the output file path format (use {0} as the file index placeholder) and the desired page numbers.
Call merger.split() passing the SplitOptions object. Each output file is written immediately.
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportSplitOptions,SplitModedefsplit_document():# Load the source PDF documentwithMerger("./input.pdf")asmerger:# Split into separate one-page files for pages 1, 2, and 3# Output files: page_0.pdf (page 1), page_1.pdf (page 2), page_2.pdf (page 3)merger.split(SplitOptions("./page_{0}.pdf",[1,2,3]))defsplit_document_by_interval():# Load the source PDF documentwithMerger("./input.pdf")asmerger:# Split into multi-page files using page boundaries [2, 4]# INTERVAL mode: pages 1 → part_0.pdf, pages 2-3 → part_1.pdf, pages 4+ → part_2.pdfmerger.split(SplitOptions("./part_{0}.pdf",[2,4],split_mode=SplitMode.INTERVAL))if__name__=="__main__":split_document()split_document_by_interval()
input.pdf is a sample file used in this example. Click here to download it.
Load source document: Merger("./input.pdf") opens the document as a context manager, ensuring resources are released automatically.
Split by exact pages (SplitOptions("./page_{0}.pdf", [1, 2, 3])): the default mode is SplitMode.PAGES, which produces one output file per listed page number. Page numbers are 1-based.
Split by interval (SplitOptions(..., [2, 4], split_mode=SplitMode.INTERVAL)): the listed numbers are treated as interval boundaries. Pages before the first boundary form the first segment, pages between each pair of boundaries form subsequent segments, and pages after the last boundary form the final segment.
Output format: the {0} placeholder in the path format is replaced with a zero-based file index for each output file.
No explicit merger.save() call is needed — split() writes output files directly.
Tip
To extract only even or odd pages from a range, use the SplitOptions overload that accepts start_number, end_number, and mode=RangeMode.ODD_PAGES (or RangeMode.EVEN_PAGES).