I need to count the number of pages in a PDF file. I have used the below code,
Public Function getNumberOfPdfPages(ByVal fileName As String) As Integer
Using sr As New StreamReader(File.OpenRead(fileName))
Dim regex As New System.Text.RegularExpressions.Regex("/Type\s*/Page[^s]")
Dim matches As MatchCollection = regex.Matches(sr.ReadToEnd())
Return matches.Count
End Using
End Function
The above code is working fine for only some PDF files (PDF file versions will be different).
Is there any restriction like the PDF file should be of that version only?
Can anyone please help me out from this issue?
Thank you.
Public Function getNumberOfPdfPages(ByVal fileName As String) As Integer
Using sr As New StreamReader(File.OpenRead(fileName))
Dim regex As New System.Text.RegularExpressions.Regex("/Type\s*/Page[^s]")
Dim matches As MatchCollection = regex.Matches(sr.ReadToEnd())
Return matches.Count
End Using
End Function
The above code is working fine for only some PDF files (PDF file versions will be different).
Is there any restriction like the PDF file should be of that version only?
Can anyone please help me out from this issue?
Thank you.