Attempting to use DeleteImage on an existing PDF

Hi,
I am attempting to delete some images from an existing PDF, but it is not working. Here is the code that I am using. I will attach the source PDF.

Imports Aspose.Pdf.Facades
'create PdfContentEditor object to delete an image
Dim objContentEditor As New PdfContentEditor()
'bind input pdf file
objContentEditor.BindPdf(docLocation & “output.pdf”)
'delete the images from the particular page
objContentEditor.DeleteImage(2, New Integer() {3})
objContentEditor.DeleteImage(2, New Integer() {4})
objContentEditor.DeleteImage(2, New Integer() {5})
'save output pdf file
objContentEditor.Save(docLocation & “output2.pdf”)

Hi Vince,


Thanks
for using our products.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-34359. We will investigate this
issue in details and will keep you updated on the status of a correction.

We apologize for your inconvenience.

Hi Vince,


We have further investigated this problem and have found that the source PDF file does not contain any image but there are Graph objects. These objects cannot be removed with DeleteImage(…) method. We are sorry for this inconvenience.

Hi Vince,


Thanks for your patience. As shared earlier, the source PDF file do not contain any image file therefore they cannot be removed using DeleteImage(…) method of PdfContentEditor class. However, you may consider using Operator classes to remove Graphics objects from PDF file. Please note that when using this approach, some text labels for the graphic images will remain in PDF file. General speaking, it is not so easy to correctly exclude graphics if images are not used. So please note that

  1. It’s not an issue in Aspose.Pdf
  2. You need to search Graphic Operators by yourself, in order to delete such “images”.

For your reference, I have also attached the resultant PDF generated over my end using Aspose.Pdf for .NET 9.2.0.

[C#]

Document doc = new Document(“c:/pdftest/output
(1).pdf”
);<o:p></o:p>

Page page = doc.Pages[2];

OperatorCollection oc = page.Contents;

// used path-painting operators

Operator[] operators = new Operator[] {

new Operator.Stroke(),

new Operator.ClosePathStroke(),

new Operator.Fill()

};

ArrayList list = new ArrayList();

foreach (Operator op in operators)

{

OperatorSelector os = new OperatorSelector(op);

oc.Accept(os);

list.AddRange(os.Selected);

}

oc.Delete(list);

doc.Save(“c:/pdftest/No_Graphics_resultant.pdf”);