Remove text from PDF

Hi Mario

My task is:

  1. Load PDF file
  2. Find text “Hello”
  3. Remove this text
  4. Save to PDF again

I am trying the next:

var page = document.Pages[0];
var textElement = page.Content.FindText("HELLO").OfType<PdfTextContent>().Reverse();


Try this:

var page = document.Pages[0];
foreach (var text in page.Content.GetText().Find("HELLO"))

Does this work for you?


Hi Mario. Thanks It works!
But May I ask you how to change “HELLO” on another word “Thanks” and save to pdf again. I mean Find and Replace text in PDF.

GemBox.Pdf currently doesn’t have an API for “Find and Replace”, but we do intend to provide one in the future.
For now, can you try using something like this:

var page = document.Pages[0];
var pageContent = page.Content;
var texts = pageContent.GetText().Find("HELLO").ToList();

foreach (var text in texts)
    using var formattedText = new PdfFormattedText();
    pageContent.DrawText(formattedText, new PdfPoint(text.Bounds.Left, text.Bounds.Bottom));

Thanks. It works perfectly.