Public Function GetNoOfPagesPDF(ByVal FileName As String) As Integer
Dim Count As Integer = 0
If FileName <> "" Then
'Open the file
Dim fstream As New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim stream As New IO.StreamReader(fstream) 'Read the contents
Dim strContents As String = stream.ReadToEnd() 'Count the Total page cound
Dim reg As System.Text.RegularExpressions.Regex = _
New System.Text.RegularExpressions.Regex("/Type\s*/Page[^s]")
Dim mat As System.Text.RegularExpressions.MatchCollection = reg.Matches(strContents)
Count = mat.Count
End If
Return Count
End Function