Move PDF Pages in Python

Move a Page from One PDF Document to Another

Aspose.PDF for Python lets you move a page (not just copy it) from one PDF to another. It removes the selected page from the original document and then adds it to a new PDF file.

Think of it as cutting out a page from one book and gluing it into another — the page no longer exists in the original file after the move.

  1. Open the source PDF document using the Document class.
  2. Select a specific page to move (in this case, page 2) — this refers to a Page.
  3. Create a new PDF document (instantiate another Document).
  4. Add the selected page to the new PDF document using the destination document’s PageCollection (for example, another_document.pages.add(page)).
  5. Delete the page from the original document via its PageCollection (for example, document.pages.delete(index)).
  6. Save both documents.

The following code snippet shows you how to move one page.

import aspose.pdf as ap

def move_page_from_one_document_to_another(
    input_file_name: str, output_file_name: str
) -> None:

    document = ap.Document(input_file_name)
    page = document.pages[2]
    another_document = ap.Document()
    another_document.pages.add(page)
    document.pages.delete(2)
    document.save(input_file_name.replace(".pdf", "_new.pdf"))
    another_document.save(output_file_name)

Move Multiple Pages from One PDF Document to Another

Unlike copying, this operation transfers the selected pages — removing them from the source file and saving them in a new PDF.

  1. Create a new, empty destination document (Document).
  2. Select multiple pages (in this case, pages 1 and 3) from the source document’s PageCollection.
  3. Loop through the selected pages and add each one to the destination document’s PageCollection.
  4. Save the destination document containing the moved pages.
  5. Delete the moved pages from the source document using its PageCollection.
  6. Save the modified source document with a new file name to preserve both versions.

The following code snippet shows how to move multiple pages.

import aspose.pdf as ap

def move_multiple_pages_from_one_document_to_another(
    input_file_name: str, output_file_name: str
) -> None:
    src_document = ap.Document(input_file_name)
    dst_document = ap.Document()
    pages = [1, 2]
    for page_index in pages:
        page = src_document.pages[page_index]
        dst_document.pages.add(page)
    # Save output files
    dst_document.save(output_file_name)
    src_document.pages.delete(pages)
    src_document.save(input_file_name.replace(".pdf", "_new.pdf"))

Move a Page to a New Location in the Same PDF Document

It shows how to move a specific page to a different position within the same document — a common need when reorganizing or editing PDF layouts.

  1. Load the input PDF document using the Document class.
  2. Select the page you want to move (page 2) — this is a Page.
  3. Add it to the end of the document using the document’s PageCollection.
  4. Delete the original page from its previous location via the PageCollection.
  5. Save the modified document as a new file.
import aspose.pdf as ap

def move_page_in_new_location_in_same_document(
    input_file_name: str, output_file_name: str
) -> None:
    src_document = ap.Document(input_file_name)

    page = src_document.pages[2]
    src_document.pages.add(page)
    src_document.pages.delete(2)

    # Save output file
    src_document.save(output_file_name)