I have a pdf and I want to delete images from the document, but the results are not as expected.
Issue 1: There are pictures in the document, but I can’t get them.
Issue 2: I wanted to clear the picture, but all content has been cleared.
void Main()
{
InitCoreComponent();
var pdf = new Aspose.Pdf.Document(@"C:\Users\54390\Downloads\8620d444c93e4301be7bc36ca19b622e.pdf");
RemoveAllImage(pdf);
pdf.Save(@"C:\Users\54390\Downloads\output.pdf");
}
public static void RemoveAllImage(Aspose.Pdf.Document doc)
{
doc.Pages.ToList().ForEach(page =>
{
var imgs = page.Resources?.Images;
if (null == imgs)
{
return;
}
//Issue 1: Can not get any image, The output is 0.
Console.WriteLine(imgs.Count);
//Issue 2: All content has been cleared.
imgs.Clear();
});
}
Input file
8620d444c93e4301be7bc36ca19b622e.pdf (335.7 KB)
Output file
output.pdf (333.9 KB)