-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCount Pages In PDF File
More file actions
48 lines (46 loc) · 1.48 KB
/
Count Pages In PDF File
File metadata and controls
48 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function OnClick(clickData)
{
// --------------------------------------------------------
DOpus.ClearOutput();
// --------------------------------------------------------
var cmd = clickData.func.command;
cmd.deselect = false; // Prevent automatic deselection
// --------------------------------------------------------
cmd.RunCommand("Set VIEW=Details");
cmd.RunCommand("Set UTILITY=otherlog")
// --------------------------------------------------------
if (clickData.func.sourcetab.selected.count == 0)
{
DOpus.Output(" (none)");
}
else
{
var ReturnText = "";
for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
{
if (eSel.item().ext.toLowerCase() == ".pdf")
{
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("pdftk.exe \"" + eSel.item().RealPath + "\" dump_data");
var input = "";
var SetCount = 0;
var PageCount = 0;
//Get Page Counts
if (!oExec.StdOut.AtEndOfStream)
{
var outputStr = oExec.StdOut.ReadAll().split('\n');
for(i=0;i<outputStr.length;i++)
if(outputStr[i].indexOf("NumberOfPages") != -1)
{
PageCount = outputStr[i].replace("NumberOfPages: ", "");
}
}
//Add to return
ReturnText += eSel.item().name + " - Pages " + (+PageCount) + "\n";
DOpus.Output(eSel.item().name + " - Pages " + (+PageCount)); //Split to log for live view
}
}
//Return to sender
cmd.RunCommand("Clipboard Set " + ReturnText);
}
}