Remove Specific PDF Pages
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
    // Define the HTML content
    const 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>
    `;

    // Create a PDF document from the HTML
    const pdf = await PdfDocument.fromHtml(html);

    // Remove pages 2 and 3 (page numbers are zero-based)
    pdf.removePage([1, 2]);

    // Save the modified PDF document
    await pdf.saveAs("page1And4.pdf");
})();
npm i @ironsoftware/ironpdf
Remove Specific PDF Pages

Remove Specific PDF Pages

To remove single or multiple pages from a PDF document, please use the removePage method. The edited PDF document can then be exported using the saveAs method of IronPDF, a powerful PDF library for .NET that allows you to create, edit, and manipulate PDF files programmatically. You can learn more about the features of IronPDF on the IronPDF official website.

Explanation:

  • IronPdf: The code utilizes IronPdf, a .NET library for PDF manipulation. Make sure to have this library installed in your project.
  • PdfDocument.FromFile(inputPath): This loads the PDF from the given file path into a PdfDocument object.
  • RemovePage(0): This method is called on the PdfDocument object to remove the first page of the PDF. Page numbering starts with 0, so 0 represents the first page.
  • SaveAs(outputPath): Any changes made to the PdfDocument object are saved to a new file specified by outputPath.
  • Console.WriteLine: Prints a completion message to the console, indicating the location of the modified PDF.

Keep in mind to replace "input.pdf" and "output.pdf" with your actual file paths.

Explore GitHub Examples for Removing PDF Pages with IronPDF
View on GitHub

Ready to Get Started?

Version:2026.10just released