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