Instantiate Merger with the path to the source document.
Create a RemoveOptions object with the list of 1-based page numbers to remove.
Call merger.remove_pages() passing the RemoveOptions object.
Call merger.save() to write the resulting document.
fromgroupdocs.mergerimportMergerfromgroupdocs.merger.domain.optionsimportRemoveOptionsdefremove_document_pages():# Load the source PDF documentwithMerger("./input.pdf")asmerger:# Remove page 2 from the documentmerger.remove_pages(RemoveOptions([2]))# Save the document with the specified page removedmerger.save("./output.pdf")if__name__=="__main__":remove_document_pages()
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.
RemoveOptions([2]): accepts a list of 1-based page numbers to remove. To remove multiple pages, include them all in the list — for example, RemoveOptions([2, 4, 6]).
merger.remove_pages(): applies the removal in memory. The original file is not modified.
merger.save("./output.pdf"): writes the resulting document (with the specified pages omitted) to the given path.
Tip
To delete pages in a range (for example, all even pages from 1 to 10), use the RemoveOptions overload that accepts start_number, end_number, and a RangeMode value.