The following example demonstrates how to remove text from a PDF document.
| Remove text (C#) |
Copy Code |
|---|---|
public static void RemoveText() { Console.WriteLine( "=== REMOVE TEXT ===" ); var outputFileName = "RemoveText.pdf"; var outputPath = TextsSample.TextsSampleOutputDirectory + outputFileName; // Loads a PdfDocument. using( var pdfInput = PdfDocument.Load( TextsSample.TextsSampleResourcesDirectory + @"Two Page Text Only - from libre office.pdf" ) ) { // Gets the first Page. var page = pdfInput.Pages.First(); // Set the text to find. var textSearchOptions = new TextSearchOptions( "License" ); // Get all the texts matching the search options in page 1. var textMatches = page.FindText( textSearchOptions ); // Remove the found texts. page.RemoveText( textMatches ); // Saves to the output document. pdfInput.SaveAs( outputPath ); Console.WriteLine( $"Info exported to path: {outputFileName}" ); } } | |