|
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
- Free VB.NET PDF SDK library for replacing PDF text in Visual Studio .NET application
- 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
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)
|