Free Support Forum - aspose.com

Delete all image from PDF

Hi,


I am using licence version of Aspose to delete all image from PDF file.
I have used .Pdf.Facades.PdfContentEditor class to delete images.
It delete all the content from the pdf file. after deleting it genrates empty PDF file.

Code which we are using to delete the images are as follows :-

Aspose.Pdf.Facades.PdfContentEditor contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
contentEditor.BindPdf(“sInputfile.pdf”);
//delete the images from the particular page
contentEditor.DeleteImage();
//save output PDF
contentEditor.Save(“outputfile.pdf”);

Please let me know the solution to overcome on this issue.

Thanks
Amol

Hi Amol,


Thanks for your inquiry. While using latest version of Aspose.Pdf for .Net 7.8.0, I’m unable to reproduce the issue. Please download and try latest Aspose.Pdf API. Hopefully your issue will be resolve. Even, If issue persist then please share your source document here. So we will test it at our end and will provide you information accordingly.

Best Regards,

Hi Tilal,


I have used aspose.Pdf for .Net 7.8.0 but still issue is not resolved.

I have try following approaches using help from your website.

Please find below two approaches and let me know your solution.

approach : 1
Aspose.Pdf.License licpdf = new Aspose.Pdf.License();
licpdf.SetLicense(System.AppDomain.CurrentDomain.BaseDirectory + “Aspose.Total.lic”);

Aspose.Pdf.Facades.PdfContentEditor contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();
contentEditor.BindPdf(sOpenPdfFilePath);
contentEditor.DeleteImage();
contentEditor.Save(sSavePdfpath);


approach : 2
Aspose.Pdf.License licpdf = new Aspose.Pdf.License();
licpdf.SetLicense(System.AppDomain.CurrentDomain.BaseDirectory + “Aspose.Total.lic”);

Document pdfDocument = new Document(sOpenPdfFilePath);
for (int i = 1; i < pdfDocument.Pages.Count; i++)
{
if (pdfDocument.Pages[i].Resources.Images.Count > 0)
{
pdfDocument.Pages[i].Resources.Images.Delete();
}
}
pdfDocument.Save(sSavePdfpath);

Thanks,
Amol

Hi Amol,


Thanks for your feedback. Both approaches work fine but we will prefer second approach as it used DOM structure. Please find sample source and resultant documents fro reference. Please double check your document, might be text also embed as image so you are getting empty document. If issue persist then please share your source document here. So we will test it at our end and suggest you accordingly.

Best Regards,