Images in watermarks

Hi Aspose,

I try to clean metadata from Images in pdf documents. For this I save image to memory as BMP and replace original with such new one. But with watermarks I have some difficulties. For that purpose, I use this code:

for (var j = 1; j <= page.Artifacts.Count; j++)
    {
        var artifact = page.Artifacts[j];
        if (artifact.Subtype == Artifact.ArtifactSubtype.Watermark && artifact.Image != null)
            {
                var imageResource = artifact.Image;
                // get the original raw image (ToStream)

                MemoryStream ms = new MemoryStream();
                imageResource.Save(ms, ImageFormat.Bmp);

                //cleaning metadata for image

                artifact.SetImage(ms);
            }
     }

The problem is that when artifact.SetImage(ms) line executes, page.Artifacts.Count in debugger shows that count is increased by 1. It seems that instead of replacing artifact’s image, Aspose duplicates artifact with new image but not remove old one.

As a workaround, I have being trying to call page.Artifacts.Delete(j) right after SetImage. In such case both artifacts removes after document is being saved which also not resolves the issue.

So, I need a suggestion how to properly handle artefact image or how to achieve my final goal (remove watermark’s images metadata).

Watermark.pdf (111.4 KB)

Best regards,
Alex Shloma

@licenses

Thank you for contacting support.

We have tried to replace the image with below code snippet but it does not remove the metadata. Therefore, a ticket with ID PDFNET-46765 has been logged in our issue management system for further investigations. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

Document doc = new Document(dataDir + "Watermark.pdf");
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
foreach (var page in doc.Pages)
{
    page.Accept(abs);
    MemoryStream memoryStream = new MemoryStream();
    for (int counter = 1; counter <= abs.ImagePlacements.Count; counter++)
    {
        ImagePlacement imagePlacement = abs.ImagePlacements[counter];
        imagePlacement.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
        imagePlacement.Replace(memoryStream);
    }
}
doc.Save(dataDir + "Replaced_19.7.pdf");

We are sorry for the inconvenience.