XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Text: Delete Text from PDF
  |  
Home ›› XDoc.PDF ›› C# PDF: Delete Text from PDF

C#.NET PDF SDK - Delete Text from PDF File in C#.NET


How to Use C# Programming Demo Code to Delete Text from PDF File with .NET PDF Component




Professional PDF SDK library for adobe PDF text deletion in Visual Studio .NET framework program


Free evaluation components able to perform PDF text deletion function in both C#.NET WinForms and ASP.NET project


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


Delete text from PDF file in preview without adobe PDF reader component installed in ASP.NET


C# class source code able to help users delete text characters at specified position from PDF in .NET console application


Able to pull text out of selected PDF page or all PDF document in .NET WinForms


Functionality to remove text format by modifying text font, size, color, etc


Other PDF edit functionalities, like add PDF text, add PDF text box and field


In document management system, users may have the need of deleting content from PDF document, like text characters. And RasterEdge .NET PDF SDK is such a qualified solution that allows C# programmers to integrate mature text deletion functionality into .NET projects. Basically, you can use robust APIs to select a PDF page, define the text character position, and remove it from PDF document.




C#.NET Project DLLs: Delete Text from PDF in C#.NET



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;


  using RasterEdge.Imaging.Basic.TextSearch;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




C#.NET Sample Code: Delete Text from One Page by Position in C#.NET



To help you have a quick start, we provide a piece of simple C# sample code here. It demonstrates how to delete a character in the first page of sample PDF file with the location of (123F, 187F).




// Open a document.
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);

// Get a text manager from the document object.
PDFTextMgr textMgr = PDFTextHandler.ExportPDFTextManager(doc);

// Get the first page from the document.
int pageIndex = 0;
PDFPage page = (PDFPage)doc.GetPage(pageIndex);

// Select char at position (127F, 187F).
PointF cursor = new PointF(127F, 187F);
PDFTextCharacter aChar = textMgr.SelectChar(page, cursor);

// Delete a selected character.
textMgr.DeleteChar(aChar);

// Output the new document.
String outputFilePath = Program.RootPath + "\\" + "output.pdf";
doc.Save(outputFilePath);





C#.NET Sample Code: Delete Specified Text from PDF File


The following C# coding example illustrates how to perform PDF text deleting function in your .NET project, according to search option.




// Open a document.
PDFDocument doc = new PDFDocument(inputFilePath);

// Set the search options.
RESearchOption option = new RESearchOption();
option.IgnoreCase = true;
option.WholeWord = true;
option.ContextExpansion = 6;

// Search and delete "iphone" from pdf file.
doc.SearchTextAndDelete("iphone", option);
doc.Save(@"C:\output.pdf");





C#.NET Sample Code: Delete Text from Specified PDF Page


The following demo code will show how to delete text in specified PDF page.




// Open a document.
PDFDocument doc = new PDFDocument(inputFilePath);

// Set the search options.
RESearchOption option = new RESearchOption();
option.IgnoreCase = true;
option.WholeWord = true;
option.ContextExpansion = 6;

int pageIndex =0;

// Search and delete "iphone" from first page.
doc.SearchTextAndDelete("iphone", option, pageIndex);
doc.Save(@"C:\output.pdf");





C#.NET PDF: Delete Text from Consecutive PDF Pages


The following demo code will show how to delete specified text in consecutive PDF page starting specified page index.




// Open a document.
PDFDocument doc = new PDFDocument(inputFilePath);

// Set the search options.
RESearchOption option = new RESearchOption();
option.IgnoreCase = true;
option.WholeWord = true;
option.ContextExpansion = 6;

int pageOffset =0;
int pageCount = 2;

// Search and delete "iphone" from first and second pages.
doc.SearchTextAndDelete("iphone", option, pageOffset, pageCount);
doc.Save(@"C:\output.pdf");





public int DeleteChar(PDFTextCharacter value)

Description:
     Delete a char value from PDF page at specified page position.

Parameters:

Return:
     Error code, 0 if success.



public void SearchTextAndDelete(String matchString, RESearchOption option)

Description:
     Delete specified string text that match the search option from PDF file.

Parameters:



public void SearchTextAndDelete(String matchString, RESearchOption option, int pageIndex)

Description:
     Delete specified string text that match the search option from specified PDF page.

Parameters:



public void SearchTextAndDelete(String matchString, RESearchOption option, int pageOffset, int pageCount)

Description:
     Delete specified string text that match the search option from specified PDF page.

Parameters: