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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse a PDF file to determine the page count 2

Status
Not open for further replies.

ilektronik

Programmer
Oct 13, 2003
7
US
Hello all -

I am a Java developer who recently was plunged by management into the world of .NET. The last six months were spent coding C# projects (I have become a fan of C# since). I am now on a VB.NET project and have zero VB experience of any kind. Here is the question:

I have a directory with multiple PDF files listed in them. There is a web application that allows users to FTP these PDF files from point A to point B. Simple stuff. Before a user sends these files anywhere, I have a display screen that displays row by row a list of the PDF's in that directory with some information on the PDF (file location, modified date, etc.) One of the pieces of information that I need to display is the number of pages that exist within the PDF.

I tried opening a random PDF in notepad and found that there is a line that has "/COUNT" that signifies the number of pages within that PDF. The question is what is the best way to simply read that page count and export it as a local variable. Thanks in advance!!
 
I don't know how the PDF headers are formatted, so that needs to be determined, but here's how I would start:
Code:
  Private Function GetPagesPDF(ByVal strFile As String) As Integer
    Dim fstream As IO.StreamReader
    Dim strLine As String
    Dim intIndex As Integer


    If IO.File.Exists(strFile) Then
      fstream = New IO.StreamReader(strFile)
      With fstream
        While .Peek() >= 0
          strLine = .ReadLine()
          intIndex = InStr(strLine, "/Count ", CompareMethod.Text)
          If intIndex > 0 Then
            GetPagesPDF = CInt(Mid(strLine, intIndex + Len("/Count ")))
            Exit While
          End If
        End While
        .Close()
      End With
    End If
  End Function


VBSlammer
redinvader3walking.gif

[sleeping]Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top