0

Looking for newer easier solution than found here: How to count pages in multiple PDF files?

or at least explanation on how to download and install cygwin

PR1
  • 21
  • 1
  • 1
    So if we have an answer we should close this question as a duplicate and answer there? Or maybe this duplicate? https://superuser.com/questions/1446208/counting-total-number-of-pages-across-multiple-pdf-files-on-the-windows-powersh Looks like that one has a pretty good answer already – Gantendo May 01 '23 at 20:21
  • For the Cygwin question: here https://www.cygwin.com/install.html – Gantendo May 01 '23 at 20:23
  • Thanks for the link. Is their a non-Cygwin solution to this? Work PC doesn't allow cygwin installs. – PR1 May 01 '23 at 20:28
  • Windows has a 'pages' field option for docx files but not pdf files as shown here: https://www.howtogeek.com/220811/how-to-get-the-page-counts-for-multiple-word-documents-at-once/ Looking for something like this but for 5000+ pdf files. – PR1 May 01 '23 at 20:32
  • PowerShell also blocked on work PC – PR1 May 01 '23 at 20:36
  • Hm lemme check something else https://stackoverflow.com/questions/1672580/get-number-of-pages-in-a-pdf-using-a-cmd-batch-file – Gantendo May 01 '23 at 20:37
  • Unless I am not seeing everything all of the solutions in 1672580 post require installs that are blocked on work PC. I tried doing the .bat file but running it doesn't produce anything. – PR1 May 01 '23 at 20:50
  • There must be a commandline utility that requires no installation that can give us this information, and then you can write a bit of batch to loop recursively. The search continues! – Gantendo May 01 '23 at 20:51
  • https://stackoverflow.com/questions/67794603/imagemagick-c-sharp-how-to-find-out-how-many-pages-in-pdf-file-api & https://stackoverflow.com/questions/1098156/number-of-pages-in-a-pdf-file & https://stackoverflow.com/questions/1672580/get-number-of-pages-in-a-pdf-using-a-cmd-batch-file & https://stackoverflow.com/questions/4134949/determine-the-number-of-pages-in-a-pdf-file & https://stackoverflow.com/questions/14644353/get-the-number-of-pages-in-a-pdf-document & https://stackoverflow.com/questions/23597825/count-the-number-of-pages-in-pdf-file – Gantendo May 01 '23 at 20:55
  • https://stackoverflow.com/questions/23597825/count-the-number-of-pages-in-pdf-file & https://stackoverflow.com/questions/14704274/how-to-write-shell-script-for-finding-number-of-pages-in-pdf & https://stackoverflow.com/questions/35629451/no-of-pages-in-pdf-file & https://stackoverflow.com/questions/54019355/count-total-number-of-pages-in-pdf-file & https://stackoverflow.com/questions/320281/determine-number-of-pages-in-a-pdf-file Why are there so many questions about this topic – Gantendo May 01 '23 at 20:55
  • Maybe try https://www.pdflabs.com/tools/pdftk-server/ and Imagemagick – Gantendo May 01 '23 at 20:56
  • Yeah, there's definitely a market for doing it with cmd and no installs. I guess having a non-work PC where installs are allowed is the workaround. – PR1 May 01 '23 at 21:00
  • Is this a one-time thing? Or do you have to do it frequently? Ngl I'd bribe IT and/or smuggle in a Raspberry Pi. If you also can't install stuff I'd try imagemagick – Gantendo May 01 '23 at 21:01
  • one-time thing, although doing things with cmd and no installs is always nice and just feels right. It's odd Windows makes this obviously popular task so complicated. – PR1 May 01 '23 at 21:11
  • In this case I wouldn't blame Windows (for once). "No one is allowed to install software" is a great policy, until it isn't. – Gantendo May 01 '23 at 21:14
  • 1
    Found a solution using Excel and VBA: https://www.extendoffice.com/documents/excel/5330-excel-vba-pdf-page-count.html – PR1 May 01 '23 at 22:39
  • 1. Open a worksheet where you want to get the Pdf files and page numbers. 2. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window. 3. Click Insert > Module, and paste the following macro in the Module Window. 4. After pasting the code, and then press F5 key to run this code, and a Browse window is popped out, please select the folder that contains the Pdf files you want to list and count page numbers, 5. And then, click OK button, all Pdf file names and page numbers are listed into the current worksheet – PR1 May 01 '23 at 22:40
  • Good work. If you want you can answer your own question below, which may be of help to someone else (or yourself if you forgot). You may have to wait a bit before you can accept it as an answer tho. – Gantendo May 01 '23 at 22:42

1 Answers1

2

Beautiful Excel and VBA solution here: https://www.extendoffice.com/documents/excel/5330-excel-vba-pdf-page-count.html

  1. Open a worksheet where you want to get the Pdf files and page numbers.
  2. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
  3. Click Insert > Module, and paste the following macro in the Module Window. VBA code: List all Pdf file names and page numbers in worksheet:
    Sub Test()
        Dim I As Long
        Dim xRg As Range
        Dim xStr As String
        Dim xFd As FileDialog
        Dim xFdItem As Variant
        Dim xFileName As String
        Dim xFileNum As Long
        Dim RegExp As Object
        Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
        If xFd.Show = -1 Then
            xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
            xFileName = Dir(xFdItem & "*.pdf", vbDirectory)
            Set xRg = Range("A1")
            Range("A:B").ClearContents
            Range("A1:B1").Font.Bold = True
            xRg = "File Name"
            xRg.Offset(0, 1) = "Pages"
            I = 2
            xStr = ""
            Do While xFileName <> ""
                Cells(I, 1) = xFileName
                Set RegExp = CreateObject("VBscript.RegExp")
                RegExp.Global = True
                RegExp.Pattern = "/Type\s*/Page[^s]"
                xFileNum = FreeFile
                Open (xFdItem & xFileName) For Binary As #xFileNum
                    xStr = Space(LOF(xFileNum))
                    Get #xFileNum, , xStr
                Close #xFileNum
                Cells(I, 2) = RegExp.Execute(xStr).Count
                I = I + 1
                xFileName = Dir
            Loop
            Columns("A:B").AutoFit
        End If
    End Sub

Copy

  1. After pasting the code, and then press F5 key to run this code, and a Browse window is popped out, please select the folder that contains the Pdf files you want to list and count page numbers, see screenshot:

  2. And then, click OK button, all Pdf file names and page numbers are listed into the current worksheet, see screenshot:

Rohit Gupta
  • 2,721
  • 18
  • 27
  • 35
PR1
  • 21
  • 1