Skip to content

Instantly share code, notes, and snippets.

@bmatusiak
Created September 6, 2012 09:12
Show Gist options
  • Save bmatusiak/3653480 to your computer and use it in GitHub Desktop.
Save bmatusiak/3653480 to your computer and use it in GitHub Desktop.
pdfPageCount.js
var fs = require("fs");
var ext = "pdf";
var fileName = './out.pdf'.toLowerCase();
var fileNameNoEXT = fileName.replace("."+ext,"");
fs.readFile(fileName,"utf8", function (err, data) {
if (err) throw err;
data = data.split("endobj")
for(var i in data){
if(data[i].indexOf("/Count") >= 0){
var strinngyLines = data[i].split("\n")
for(var j in strinngyLines){
if(strinngyLines[j].indexOf("/Count") >= 0){
var newFileName = fileNameNoEXT+" ("+strinngyLines[j].slice(7)+"-Pages)."+ext;
fs.rename(fileName, newFileName, function (err) {
if (err) throw err;
console.log("compleate")
});
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment