Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count number of pages in a pdf file

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
DE
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.
 
I tried to open the PDF files in notepad, then if the notepad text doesnt containf "Count" word, the above function is not returning the number of pages.

Is there any other way to count if the PDF file does not contain "Count" word.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top