Delete PDF Pages programmatically C#

The following code snippet also work with Aspose.PDF.Drawing library.

You can delete pages from a PDF file using Aspose.PDF for .NET. To delete a particular page from the PageCollection collection.

Delete Page from PDF File

  1. Call the Delete method and specify the page’s index.
  2. Call the Save method to save the updated PDF file. The following code snippet shows how to delete a particular page from the PDF file using C#.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DeletePageFromPdfFile()
{
    // The path to the documents directory
    string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
    // Open document
    using (var document = new Aspose.Pdf.Document(dataDir + "DeleteParticularPage.pdf"))
    {
        // Delete a particular page
        document.Pages.Delete(2);
        // Save updated PDF
        document.Save(dataDir + "DeleteParticularPage_out.pdf");
    }
}