How to Start Convert PDF Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

VB.NET PDF Text Library
How to find and replace Text in PDF in Visual Basic .NET Windows Forms, ASP.NET apps


VB.NET Programming Demo Code to Replace Text in PDF Document in VB.NET Class





In this vb.net tutorial, you will learn how to find and replace text in PDF documents using VB.NET code in Visual Studio applications.

  • Search, find, replace text in PDF with regular expression
  • Replace vertical text in PDF document
  • Easy to develop in Windows Forms, WPF applications, ASP.NET using VB.NET

How to find, replace text in PDF file using Visual Basic .NET

  1. Download XDoc.PDF Text VB.NET library
  2. Install vb library to replace text in PDF
  3. Step by Step Tutorial










  • Free VB.NET PDF SDK library for replacing PDF text in Visual Studio .NET application
  • View C# code tutorial at How to replace text in PDF using C#
  • Able to perform PDF text replacing in .NET WinForms and ASP.NET webpage
  • Find and replace text in PDF file in preview without adobe PDF reader component installed
  • Able to pull text out of selected PDF page or all PDF document in VB.NET
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Online .NET framework freeware download and VB.NET class source code
  • A Professional VB.NET PDF edit control compatible with Windows system


asp.net remove image from pdf page, asp.net mvc pdf editor, asp.net pdf preview, display image in repeater asp net, how to display pdf file in asp.net c#, asp.net add text to pdf file, mvc 5 display pdf in view.







VB.NET Search and replace text from the specified page(s)


The VB.NET example source code below shows how to do text search, and replace text from PDF page ranges.



Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\output.pdf"

' Open file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Search text "RasterEdge"
Dim matchString As String = "RasterEdge"
' Set search option
Dim searchOps As RESearchOption = New RESearchOption()
searchOps.MatchString = matchString
searchOps.IgnoreCase = True
searchOps.WholeWord = False
searchOps.ContextExpansion = 0
' Set search range (from page 1 to 3)
Dim pageOffset As Integer = 0
Dim pageCount As Integer = 3

' New string to replace the old value.
Dim replaceText As String = "[Replace]"
' Set replace text settings
Dim replaceOps As PDFDocument.TextReplaceOption = New PDFDocument.TextReplaceOption()
replaceOps.TextFont = New System.Drawing.Font("Arial", 16.0F, FontStyle.Regular)
replaceOps.TextColor = System.Drawing.Color.Red
' Apply string replacing
doc.Replace(matchString, replaceText, searchOps, pageOffset, pageCount, replaceOps)

' Save file
doc.Save(outputFilePath)






VB.NET search and replace text from the specified page region


The vb.net example source code below shows how to do text search, and replace text from a PDF page region.



Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\output.pdf"

' Open file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Search text "RasterEdge"
Dim matchString As String = "RasterEdge"
' Set search option
Dim searchOps As RESearchOption = New RESearchOption()
searchOps.MatchString = matchString
searchOps.IgnoreCase = True
searchOps.WholeWord = False
searchOps.ContextExpansion = 0
' Set target page region in the 1st page.
Dim pageIndex As Integer = 0
' Region: start Point(0, 0), with = 500, height = 300.Unit: pixel(in 96 dpi).
Dim pageRegion As RectangleF = New RectangleF(0, 0, 500, 300)

' New string to replace the old value.
Dim replaceText As String = "[Replace]"
' Set replace text settings
Dim replaceOps As PDFDocument.TextReplaceOption = New PDFDocument.TextReplaceOption()
replaceOps.TextFont = New System.Drawing.Font("Arial", 16.0F, FontStyle.Regular)
replaceOps.TextColor = System.Drawing.Color.Red
' Apply string replacing
doc.Replace(matchString, replaceText, searchOps, pageIndex, pageRegion, replaceOps)

' Save file
doc.Save(outputFilePath)






VB.NET search and replace text with regular expression from the specified page(s)


The vb.net example source code below shows how to do text search with regular expression, and replace text from pdf page ranges.



Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\output.pdf"

' Open file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Search pattern for URL
Dim pattern As String = "\b(\S+)://(\S+)\b"
Dim regexOps As RegexOptions = RegexOptions.IgnoreCase
' Set search range (from page 1 to 3)
Dim pageOffset As Integer = 0
Dim pageCount As Integer = 3

' New string to replace the old value.
Dim replaceText As String = "[Replace]"
' Set replace text settings
Dim replaceOps As PDFDocument.TextReplaceOption = New PDFDocument.TextReplaceOption()
replaceOps.TextFont = New System.Drawing.Font("Arial", 16.0F, FontStyle.Regular)
replaceOps.TextColor = System.Drawing.Color.Red
' Apply string replacing
doc.Replace(pattern, regexOps, replaceText, pageOffset, pageCount, replaceOps)

' Save file
doc.Save(outputFilePath)






VB.NET search and replace text with regular expression from specified page region


The vb.net example source code below shows how to do text search with regular expression, and replace text from pdf page region.



Dim inputFilePath As String = "C:\1.pdf"
Dim outputFilePath As String = "C:\output.pdf"

' Open file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)

' Search pattern for URL
Dim pattern As String = "\b(\S+)://(\S+)\b"
Dim regexOps As RegexOptions = RegexOptions.IgnoreCase
' Set target page region in the 1st page.
Dim pageIndex As Integer = 0
' Region: start Point(0, 0), with = 500, height = 300.Unit: pixel(in 96 dpi).
Dim pageRegion As RectangleF = New RectangleF(0, 0, 500, 300)

' New string to replace the old value.
Dim replaceText As String = "[Replace]"
' Set replace text settings
Dim replaceOps As PDFDocument.TextReplaceOption = New PDFDocument.TextReplaceOption()
replaceOps.TextFont = New System.Drawing.Font("Arial", 16.0F, FontStyle.Regular)
replaceOps.TextColor = System.Drawing.Color.Red
' Apply string replacing
doc.Replace(pattern, regexOps, replaceText, pageIndex, pageRegion, replaceOps)

' Save file
doc.Save(outputFilePath)