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: Replace Text in PDF
  |  
Home ›› XDoc.PDF ›› C# PDF: Replace Text in PDF

C#.NET PDF SDK - Replace Text in PDF File in C#.NET


C# Demo Code to Replace Text in PDF File with C#.NET PDF Library





Free PDF SDK library for enable users the ability to replace PDF text in Visual C# .NET framework project


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


A Professional C#.NET PDF edit control able to replace PDF text in .NET WinForms and ASP.NET web sever project


C#.NET class source codes for manipulating PDF text replacing function in Visual Studio .NET


Replace text in PDF file in preview on ASPX webpage


Able to replace PDF text in ASP.NET program


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


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




C#.NET DLLs: Replace Text in 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 PDF Demo: Replace Text in PDF File


The following C# coding example illustrates how to perform PDF text replacing 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 = 10;

// Replace "RasterEdge" with "Image".
doc.Replace("RasterEdge", "Image", option);
doc.Save(@"C:\output.pdf");





C#.NET PDF Demo: Replace Text in Specified PDF Page


The following demo code will show how to replace 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 = 10;

int pageIndex = 0;

// Replace "RasterEdge" with "Image" in first page.
doc.Replace("RasterEdge", "Image", option, pageIndex);
doc.Save(@"C:\output.pdf");





C#.NET PDF Demo: Replace Text in Consecutive PDF Pages


The following demo code will show how to replace text in consecutive PDF page starting from 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 = 10;

int pageOffset = 0;
int pageCount = 2

// Replace "RasterEdge" with "Image" in first and second pages.
doc.Replace("RasterEdge", "Image", option, pageOffset, pageCount);
doc.Save(@"C:\output.pdf");




public void Replace(String oldString, String newString, RESearchOption option)

Description:
     Replace old string by new string in the PDF file.

Parameters:



public void Replace(String oldString, String newString, RESearchOption option, int pageIndex)

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

Parameters:



public void Replace(String oldString, String newString, RESearchOption option, int pageOffset, int pageCount)

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

Parameters: