Related blog post: Find, Replace, Hide Text in PDF using C#
Last active
February 19, 2022 10:43
-
-
Save GroupDocsGists/350afb0feb5749b5381d4c8806792b43 to your computer and use it in GitHub Desktop.
Find and Replace Text, Phrase, Words in PDF Documents using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find text in PDF and hide it by drawing rectangle over it using C# | |
using (Redactor redactor = new Redactor(@"path/document.pdf")) | |
{ | |
redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions(System.Drawing.Color.Black))); | |
redactor.Save(new SaveOptions() { AddSuffix = true, RasterizeToPDF = false }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find exact phrase and replace it with some other text using C# | |
using (Redactor redactor = new Redactor(@"path/document.pdf")) | |
{ | |
redactor.Apply(new ExactPhraseRedaction("John Doe", new ReplacementOptions("[censored]"))); | |
redactor.Save(new SaveOptions() { AddSuffix = true, RasterizeToPDF = false }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find exact phrase (case-sensitive) and replace it with some other text using C# | |
using (Redactor redactor = new Redactor(@"path/document.pdf")) | |
{ | |
redactor.Apply(new ExactPhraseRedaction("John Doe", true /*isCaseSensitive*/, new ReplacementOptions("[censored]"))); | |
redactor.Save(new SaveOptions() { AddSuffix = true, RasterizeToPDF = false }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find text using regular expression and replace it with some other text using C# | |
using (Redactor redactor = new Redactor(@"path/document.pdf")) | |
{ | |
redactor.Apply(new RegexRedaction("\\d{2}\\s*\\d{2}[^\\d]*\\d{6}", new ReplacementOptions("[censored]"))); | |
redactor.Save(new SaveOptions() { AddSuffix = true, RasterizeToPDF = false }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment