IRONSOFTWAREHOME
Remove Specific PDF Pages
from ironpdf import *
 
html = """<p> Hello Iron</p>
    <p> This is 1st Page </p>
    <div style='page-break-after: always;'></div>
    <p> This is 2nd Page</p>
    <div style='page-break-after: always;'></div>
    <p> This is 3rd Page</p>
    <div style='page-break-after: always;'></div>
    <p> This is 4th Page</p>"""

renderer = ChromePdfRenderer()
pdf = renderer.RenderHtmlAsPdf(html)

# Remove pages 2 and 3. Python uses zero-based indexing.
pdf.RemovePages(1, 2)

pdf.SaveAs("Page1And4.pdf")
pip install ironpdf
Remove Specific PDF Pages

Remove Specific PDF Pages

IronPDF for Python can remove one or more pages from an existing PDF document using the RemovePages method, returning a modified PdfDocument with the specified pages deleted.

Getting Started

Create or load a PdfDocument, then call RemovePages with the zero-based indexes of the pages you want to delete. The remaining pages are renumbered automatically and the modified document can be saved with SaveAs.

Understanding the Code

  • RenderHtmlAsPdf(html): Creates a multi-page PDF from HTML. The page-break-after: always CSS rule separates the content into individual pages.
  • RemovePages(start, end): Removes pages from the document. Arguments are zero-based page indexes. In this example, RemovePages(1, 2) removes the second and third pages, leaving only pages 1 and 4.
  • SaveAs(path): Saves the modified document - with the specified pages removed - to the given file path.

Zero-Based Page Indexing

All page operations in IronPDF use zero-based indexes. To remove the second page of a document, pass index 1. To remove the last page, pass pdf.PageCount - 1.

Removing Non-Contiguous Pages

To remove pages that are not in a contiguous range, call RemovePages multiple times or build a list of specific page indexes to remove. Start from the highest index to avoid index shifting after each removal.

Learn to edit PDF pages with IronPDF for Python!

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF for Python
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999