-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathgetPDFPageLength.jsx
More file actions
48 lines (41 loc) · 1018 Bytes
/
getPDFPageLength.jsx
File metadata and controls
48 lines (41 loc) · 1018 Bytes
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
f = File.openDialog ("select PDF file...");
alert(pdfPageCount(f));
function pdfPageCount(fNm)
{
if(fNm == null) return -1;
var f = new File(fNm);
f.encoding = "Binary";
if(!f.open("r")) return -1;
f.seek(0, 0);
var str = f.read();
f.close();
if(!str) return -1;
var ps = str.match(/<<\/Count\s\d+.+?>>/g);
if(ps!=null)
{
for (var i=0;i<ps.length;i++)
{
if (ps[i].indexOf("/Type/Pages")>-1)
{
ps = ps[i].match(/<<\/Count\s(\d+)/);
lim = parseInt(ps[1]);
if(isNaN(lim)) return -1;
return lim;
}
}
}
ps = str.match(/<<.+?\/Type\s\/Pages.+?>>/);
if(ps!=null)
{
ps = ps[0].match(/\/Count\s(\d+)/);
lim = parseInt(ps[1]);
if(isNaN(lim)) return -1;
return lim;
}
var ix, _ix, lim;
ix = str.indexOf("/N ");
_ix = str.indexOf("/T", ix);
lim = parseInt(str.substring(ix+3, _ix));
if(isNaN(lim)) return -1;
return lim;
}