Visual Basic Programming Course
How to Extract Text from PDF File in VB Net
![]() |
Visual Basic Tips on How to Manipulate PDF Files |
💽Intro
This course blog discusses dealing with PDF File Format (PDF). Since Adobe Acrobat PDF reader is the best tool until today, then I will use it. iTextSharp is the most common well known tool for manipulating PDF Files in most of development environments.
As stated here , there is a new release called itext7 which adds new security features when you move to itext7, you could get either commercial copy or AGPL from their official website.
Unless you purchase a commercial License, you are not permitted to change the PDF Info concerning 'PDF Producer'.
You can find Documentations on iTextSharp 5.0 here
📃Requirements
- Microsoft Windows 32bit or 64bit
- Microsoft Visual Studio 2010
- iTextSharp 5.5.13.2 <<Download it from NuGet>> AGPL3 License 'Open Source'
- Awesomium 1.7.5 <<Download it from NuGet>>
💥Visual Basic Project Logic
- Open PDF File using iTextSharp 5.5.13.2
- Search for Word within PDF Text
- Display a PDF File with Highlighted Search Results
- Stamp the New PDF File with Highlighted Search Results with Watermark.
The application Life Cycle is as follows :
- User opens the Application.
- User chooses the PDF File.
- User attempts to search for a word or a phrase.
- Application opens the PDF File and get the all Text within.
- Application returns the number of pages in and the search results count in the PDF File.
- Application replaces the search results with highlighted search results.
- Application stamps the Temp PDF File with Watermark image.
- Application creates a new PDF File 'Temp file' with the new highlighted search results.
- Application displays the Temp PDF File with highlighted search results.
- Application copies and pastes the Temp PDF File in the Project Directory 'overwrites it'
- user closes the application.
- Application removes the Temp PDF File.
👇Visual Basic Project Design
- - We will need a PDF File sample to use it in our a Search task. <<Call it GNU GPL.pdf>>
- - Create a new Visual Basic WinForms Project VS2010
- - .NET Framework 4.0
- - Form1.vb design is as follows:
👩💻Visual Basic Code
VB .NET Code for choosing PDF File on Form1 TxtPdfFile.Text, using OpenFileDialog
Try
Using OFD As New OpenFileDialog With {
.CheckPathExists = True,
.Filter = ("PDF File Format *pdf|*.pdf"),
.DefaultExt = "pdf",
.Multiselect = False,
.RestoreDirectory = True,
.InitialDirectory = (Application.StartupPath),
.SupportMultiDottedExtensions = False}
If OFD.ShowDialog = System.Windows.Forms.DialogResult.OK Then
TxtPdfPath.Text = OFD.FileName
End If
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
👩💻Visual Basic Code for starting PDF File Reader using iTextSharp
Private strSource As String = PDF_FILE_LOCATION
Using pdfFileReader = New PdfReader(strSource)
End Using
🔬GitHub Repo - Full VB .NET Project iTextSharp
Visit GitHub Repo
♥ Here are some online Visual Basic lessons and courses:
No comments:
Post a Comment