PDF number of pages

pepepito78

New member
Local time
Today, 17:54
Joined
Mar 7, 2020
Messages
15
Good afternoon, do you know any VBA code that returns the number of pages of a pdf file?

Thank you
 
Hi. Not off hand, but it might require the use of Acrobat API, which means you'll need the full version of Adobe Acrobat. Do you have it?
 
Hi. Not off hand, but it might require the use of Acrobat API, which means you'll need the full version of Adobe Acrobat. Do you have it?
No, I dont have, but I used:

Function NumeroPag(El_Fichero As String) As Integer

Dim Cadena As String
Dim NumeroF As Long
Dim ObjetoPDF As Object
Cadena = ""
Set ObjetoPDF = CreateObject("VBscript.RegExp")
ObjetoPDF.Global = True
ObjetoPDF.Pattern = "/Type\s*/Page[^s]"
NumeroF = FreeFile
Open (El_Fichero) For Binary As #NumeroF
Cadena = Space(LOF(NumeroF))
Get #NumeroF, , Cadena
Close #NumeroF

NumeroPag = ObjetoPDF.Execute(Cadena).Count

End Function

but is there a file that works
 
No, I dont have, but I used:

Function NumeroPag(El_Fichero As String) As Integer

Dim Cadena As String
Dim NumeroF As Long
Dim ObjetoPDF As Object
Cadena = ""
Set ObjetoPDF = CreateObject("VBscript.RegExp")
ObjetoPDF.Global = True
ObjetoPDF.Pattern = "/Type\s*/Page[^s]"
NumeroF = FreeFile
Open (El_Fichero) For Binary As #NumeroF
Cadena = Space(LOF(NumeroF))
Get #NumeroF, , Cadena
Close #NumeroF

NumeroPag = ObjetoPDF.Execute(Cadena).Count

End Function

but is there a file that works
Hi. What do you mean by "but is there a file that works?" What happened when you tried that code?
 
It has always worked, but today I received pdf files created differently and it does not read the number of pages
 
It has always worked, but today I received pdf files created differently and it does not read the number of pages
Re: bolded part in your statement, is that true? Did the code use to work on a different set of PDF files created differently than the set of files you're using now?
 
It is a pdf created by another application to the usual one from which the number of pages is not obtained
 
It is a pdf created by another application to the usual one from which the number of pages is not obtained
I guess that means your code is not compatible with the new set of PDF files. Do you know if the new set of PDF files are OCR'd or are they just images (meaning, the text on the pages cannot be "read" by the computer)? For example, can you select a word or a character or a sentence using the mouse?
 
if it can be selected, the application reads binary and looks for the text 'page count' and in this new pdf it does not exist, so I wanted to use another way to do it
 
if it can be selected, the application reads binary and looks for the text 'page count' and in this new pdf it does not exist, so I wanted to use another way to do it
Okay, that's what I understood in your original post. You want to "actually count the pages" in a PDF document rather than rely on some text for pagination in the file, correct? If so, the only way I can think of is by using Acrobat API. I'm sure there are other ways, but I haven't tried any of them. Since you don't have a full version of Acrobat, the API approach won't work for you. You might look up PDFtk and see if they may have something you can use. Good luck!
 
Thank you!
Hi. You're welcome. Sorry I wasn't able to help much. Hope you find an answer using PDFtk. If you do, please consider sharing the solution with us. Cheers!
 

Users who are viewing this thread

Back
Top Bottom