GroupDocs.Merger for Python via .NET lets you swap the positions of any two pages within a document. The result is a new document where the two specified pages have exchanged positions — all other pages remain in their original order. The swap is configured through SwapOptions.
Here are the steps to swap document pages:
Instantiate Merger with the path to the source document.
Create a SwapOptions object with the two 1-based page numbers to exchange.
Call merger.swap_pages() passing the SwapOptions object.
Call merger.save() to write the resulting document.
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportSwapOptionsdefswap_document_pages():# Load the source PDF documentwithMerger("./input.pdf")asmerger:# Swap page 1 and page 3 — they will exchange positions in the outputmerger.swap_pages(SwapOptions(1,3))# Save the document with the pages swappedmerger.save("./output.pdf")if__name__=="__main__":swap_document_pages()
input.pdf is a sample file used in this example. Click here to download it.