Column to display page count in Word and PDF documents

The following script creates a column named "Pages," which displays the page count for both Word documents (native to Opus) and PDF documents.

To obtain the page count for PDF documents, you need the “PDF Info” tool (Poppler). Once downloaded, it can be copied to any location. However, the path to the "pdfinfo.exe" file must be specified in the script. By default, the path is "C:\Program Files (x86)\Poppler\Library\bin\pdfinfo.exe."

To install the script, simply download the "Script pages.opusscriptinstall" file and click the OK button. Once the script is installed and "PDF Info" is in the correct location, simply activate the "Pages" column.

Script pages.opusscriptinstall (1.2 KB)
"PDF Info" library

function OnInit(initData) {
    initData.name = 'Pages';
    initData.desc = 'Display page count in Word and PDF documents';
    initData.version = '1.1';
    initData.copyright = '(c) 2025 DASOTA';
    initData.default_enable = true;
}

function OnAddColumns(addColData) {
    var col = addColData.AddColumn();
    col.name = 'Pages';
    col.label = 'Pages';
    col.justify = 'center';
    col.type = 'number';
    col.method = 'OnGet';
}

function OnGet(getData) {
    var item = getData.item;
    if (!item || item.is_dir) {
        getData.value = "";
        return;
    }

    var ext = item.ext.toLowerCase();
    var pages = "";

    try {
        // If it's PDF, use pdfinfo.exe
        if (ext === ".pdf") {
            var shell = new ActiveXObject("WScript.Shell");
            var fso = new ActiveXObject("Scripting.FileSystemObject");
            var pdfinfoPath = "C:\\Program Files (x86)\\Poppler\\Library\\bin\\pdfinfo.exe"; // Path to the pdfinfo.exe file
            var tempFile = shell.ExpandEnvironmentStrings("%TEMP%") + "\\pdfinfo_output.txt";
            var command = 'cmd /c "' + '"' + pdfinfoPath + '" "' + item.realpath + '" > "' + tempFile + '"' + '"';

            shell.Run(command, 0, true);

            if (fso.FileExists(tempFile)) {
                var file = fso.OpenTextFile(tempFile, 1);
                while (!file.AtEndOfStream) {
                    var line = file.ReadLine();
                    var match = line.match(/^Pages:\s*(\d+)/i);
                    if (match) {
                        pages = parseInt(match[1], 10);
                        break;
                    }
                }
                file.Close();
                fso.DeleteFile(tempFile, true);
            }
        } else {
            // If it's Word, use Opus internal metadata
            if (item.metadata && item.metadata.doc && item.metadata.doc.pages) {
                pages = item.metadata.doc.pages;
            }
        }
    } catch (e) {
        pages = "";
    }

    getData.value = pages;
}
3 Likes

You can also use:

Thank you very much, @Leo, for the comment. I tried @errante's recommendation (Shell > Pages) (System.Document.PageCount), but it didn't work for me. It only shows the page count of Word documents, the same behavior as Documents > Pages (item.metadata.doc.pages).

That's why I needed to create this simple script. Initially, the script only showed the page count of PDF documents; and it had to have two columns enabled: one to show the page count of Word documents (Opus's own) and another column to show the page count of PDF documents. Later, I had the idea of ​​adding the ability to also show the page count of Word documents to the script. This way, I would only need one column, which is the current output of the script. Thanks again, @Leo, @errante, and @Hardkorn.

PDF-XChange Editor works for me and agrees with ExifTool regarding the number of pages in .pdf documents.

PDF-XChange.Editor.10.6.0.396.x64
Directory Opus 13.15.2.0 build 9274 English
Windows 11 24H2 build 26100.4061 on AMD64
1 Like

I use PDFelement, and I uninstalled it and installed PDF-XChange Editor to avoid possible errors or conflicts, and even then, I still couldn't get it to work with PDF-XChange Editor.

Great for those who can do it without a script, but for those of us who can't, this script can help, regardless of the program we have installed to manage our PDFs; we just need "PDF Info."

Thanks a lot @xlp!

Agreed, this looks like a good option for people who can't use the other ones.

1 Like

When installing the suggested program (Pdf xchange), make sure that "shell extension" (or something with the word "shell") is checked prior to installation. I believe that is what enables access to the pages property.

Alternatively, you could use this utility, which on its website states it does the same thing (I haven't tried it).

2 Likes

Hi @errante, I've reinstalled PDF-XChange Editor, this time using a custom install, using the "Shell Extensions" option you mentioned, and the Shell > Pages column actually shows the pages in PDF documents. Anyway, the script continues to be useful for anyone using another PDF manager. Thank you very much and a big hug!

2 Likes