Hi Aspose team,
We recently encountered a problem while using Aspose.Pdf. We have a test file. If we try to delete pages, then save file, then delete, then save, repeat these operations several times, an exception will be thrown.
We took a screenshot of the thrown exceptions.
1629969281783_CB653D3B-528A-4220-A42E-F765DDA73EC4.png (38.1 KB)
exception2.png (46.8 KB)
This is the sample code we wrote, which simplifies the original code:
var doc = new Aspose.Pdf.Document(@"C:\Users\User\Desktop\TestFile.pdf");
while (true)
{
var pages = new int[] { 1 };
string newPath = @"C:\Users\User\Desktop\New\" + doc.Pages.Count + ".pdf";
if (doc.Pages.Count > 1)
{
doc.Pages.Delete(pages);
doc.Save(newPath);
}
else
{
break;
}
}
But if add a line “doc = new Aspose.Pdf.Document(newPath);” after “doc.Save(newPath);” then no exception will be thrown.
This is our test file:
TestFile.pdf (2.2 MB)
Please take a look, thank you.