GroupDocs.Merger for Python via .NET lets you set Portrait or Landscape orientation for specific pages (or all pages) of a Word document. The orientation is configured through OrientationOptions and applied with merger.change_orientation().
Here are the steps to change the page orientation:
Instantiate Merger with the path to the source document.
Call merger.change_orientation() passing the OrientationOptions object.
Call merger.save() to write the resulting document.
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportOrientationOptions,OrientationModedefchange_page_orientation():# Load the source Word documentwithMerger("./input.pdf")asmerger:# Set pages 1 and 2 to Landscape orientationmerger.change_orientation(OrientationOptions(OrientationMode.LANDSCAPE,[1,2]))# Save the document with the updated page orientationsmerger.save("./output.pdf")if__name__=="__main__":change_page_orientation()
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 on exit.
OrientationOptions(OrientationMode.LANDSCAPE, [1, 2]): the first argument is the orientation enum; the second argument is a list of 1-based page numbers. Use OrientationMode.LANDSCAPE or OrientationMode.PORTRAIT.
merger.change_orientation(): the correct Python method name. Do not use merger.orientation() — that method does not exist.
merger.save("./output.pdf"): writes the document with the updated page orientations to the specified path.
Tip
Page orientation changes are primarily meaningful for word-processing formats such as DOCX and DOC. Using change_orientation() on PDF files rewrites the page layout; for visual rotation of PDF page content, use Rotate pages instead.