usmanazizgroupdocs
7/6/2017 - 8:05 AM

RemoveXObjectWithParticularTextFormatting.cs

// For complete examples and data files, please go to https://github.com/groupdocs-watermark/GroupDocs.Watermark-for-.NET
using (PdfDocument doc = Document.Load<PdfDocument>(Utilities.MapSourceFilePath(FilePath)))
{
    foreach (PdfPage page in doc.Pages)
    {
        for (var i = page.XObjects.Count - 1; i >= 0; i--)
        {
            foreach (var fragment in page.XObjects[i].FormattedTextFragments)
            {
                if (fragment.ForegroundColor == Color.Red)
                {
                    page.XObjects.RemoveAt(i);
                    break;
                }
            }
        }
    }
    doc.Save();
}