To remove a page from a PageCollection in Aspose.PDF, you should use the Delete method instead of trying to remove a page directly with the Remove method, which is not supported and can lead to a NotSupportedException.
Here’s how you can delete a specific page from a PDF document:
C# Example
using System;
using Aspose.Pdf;
namespace Aspose.Pdf.Examples
{
public class DeleteParticularPage
{
public static void Run()
{
// Load the PDF document
Document pdfDocument = new Document("path/to/your/document.pdf");
// Delete the specific page (e.g., page 2)
pdfDocument.Pages.Delete(2);
// Save the updated PDF document
pdfDocument.Save("path/to/your/updated_document.pdf");
Console.WriteLine("Particular page deleted successfully.");
}
}
}
Java Example
import com.aspose.pdf.Document;
public class DeleteParticularPageFromThePDFFile {
public static void main(String[] args) {
// Load the PDF document
Document pdfDocument = new Document("path/to/your/document.pdf");
// Delete the specific page (e.g., page 3)
pdfDocument.getPages().delete(3);
// Save the updated PDF document
pdfDocument.save("path/to/your/updated_document.pdf");
System.out.println("Particular page deleted successfully.");
}
}
In these examples, replace "path/to/your/document.pdf" with the actual path to your PDF file. The Delete method allows you to specify the page number you want to remove, and it will effectively delete that page from the document.
If you want to remove an empty page specifically, you can check if the page is empty before calling the Delete method. This approach should help you achieve your goal without encountering the NotSupportedException.
For more details, you can refer to the examples provided in the Aspose documentation here and here.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-58852
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.