Move page

GroupDocs.Merger for Python via .NET lets you relocate any page to a different position within a document. All other pages shift to accommodate the move. The operation is configured through MoveOptions.

Here are the steps to move a document page:

  • Instantiate Merger with the path to the source document.
  • Create a MoveOptions object specifying the current page number and the target position.
  • Call merger.move_page() passing the MoveOptions object.
  • Call merger.save() to write the resulting document.
from groupdocs.merger import Merger
from groupdocs.merger.domain.options import MoveOptions

def move_document_page():
    # Load the source PDF document
    with Merger("./input.pdf") as merger:
        # Move page 4 to position 1 (the beginning of the document)
        merger.move_page(MoveOptions(4, 1))
        # Save the document with the updated page order
        merger.save("./output.pdf")

if __name__ == "__main__":
    move_document_page()

input.pdf is a sample file used in this example. Click here to download it.

Binary file (PDF, 418 KB)

Download full output

Explanation

  • Load source document: Merger("./input.pdf") opens the document as a context manager, ensuring resources are released on exit.
  • MoveOptions(4, 1): the first argument is the current 1-based page number to move; the second argument is the 1-based target position. In this example, page 4 is inserted at position 1, pushing the original pages 1–3 forward by one.
  • merger.move_page(): the correct Python method name (singular). The equivalent .NET method is MovePage.
  • merger.save("./output.pdf"): writes the resulting document with the page in its new position.
Tip
To exchange the positions of two pages rather than inserting one at a new position, use Swap pages instead.

API reference

See also