The following script generates a column named "PDF pages" to display the page count of PDF files. To obtain the page numbers, use Poppler's "PDF Info."
The script works fine, but the "PDF Info" window appears every time it analyzes a PDF file. Could someone help me get "PDF Info" to run in the background? Thank you very much.
PDF pages.js.txt (1.3 KB)
PDF Info
function OnInit(initData) {
initData.name = "PDF pages";
initData.desc = "Column to display the number of pages in PDF files";
initData.version = "1.0";
initData.copyright = "(c) 2025 DASOTA";
initData.default_enable = true;
}
function OnAddColumns(addColData) {
var col = addColData.AddColumn();
col.name = "PDFpages";
col.label = "PDF pages";
col.justify = "right";
col.autorefresh = true;
col.type = "number";
col.method = "OnGet";
}
function OnGet(getData) {
var item = getData.item;
var ext = item.ext ? item.ext.toLowerCase() : "";
if (ext !== ".pdf") {
getData.value = "";
return;
}
var shell = new ActiveXObject("WScript.Shell");
var pdfinfoPath = "C:\\Poppler\\Library\\bin\\pdfinfo.exe"; // Path to the pdfinfo.exe file
try {
var exec = shell.Exec('"' + pdfinfoPath + '" "' + item.realpath + '"');
var pages = "";
while (!exec.StdOut.AtEndOfStream) {
var line = exec.StdOut.ReadLine();
if (line.match(/^Pages:\s*(\d+)/i)) {
pages = RegExp.$1;
break;
}
}
getData.value = pages;
} catch (e) {
getData.value = "";
}
}