Code:
Sub pdf()
Const sFile As String = "C:\test\1.pdf"
Dim f As Integer
Dim byt As Byte
Dim str As String, str1 As String
f = FreeFile
Open sFile For Binary Access Read As #f
Do While Loc(f) < LOF(f)
Get f, , byt
str1 = str1 & byt & vbNewLine
Loop
Close m
''' str1
''' different from the output when I use C# StreamReader to extract the data from the pdf file
End Sub
I guess there are many problems to be resolved if I really want to use VBA to count the pages of a pdf file.
First, I bet there is something to do with Binary.
The error "Input past end of file" seems to be caused by reading binary files and I think using Loc() could have helped solve it.
Second, I declare a variable for the binary data. I think it works with the binary data extracted from the pdf file.
But third, the output (string str1) is still different from what I get from a C# code (which works well to count the pages of a pdf file).
Anyway, I think I still need to be working hard on it since even I get the page count from the C# code. It cannot be used in Excel.