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;
}