1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
Sub fGetPagesTotal(psPath As String)
Dim sFileName As String, sFileNamePath As String
Dim i As Long
sFileName = Dir(psPath & "*.pdf", vbDirectory)
i = 1
Do While sFileName <> ""
sFileNamePath = psPath & sFileName
typPdfAttribut.pdfName = sFileName
typPdfAttribut.pageNbr = GetPageNum(sFileNamePath)
typPdfAttribut.code = Right(Left(sFileName, Len(sFileName) - 4), 1)
Call fAddAttribut
i = i + 1
sFileName = Dir
Loop
MsgBox "Total of " & i - 1 & " PDF files have been found" & vbCrLf, vbInformation, "Report..."
End Sub
Function GetPageNum(PDF_File As String)
'Haluk 19/10/2008
Dim FileNum As Long
Dim strRetVal As String
Dim RegExp
Set RegExp = CreateObject("VBscript.RegExp")
RegExp.Global = True
RegExp.Pattern = "/Type\s*/Page[^s]"
FileNum = FreeFile
Open PDF_File For Binary As #FileNum
strRetVal = Space(LOF(FileNum))
Get #FileNum, , strRetVal
Close #FileNum
GetPageNum = RegExp.Execute(strRetVal).Count
End Function |
Partager