I just want to know, how to write a simple code to count no.of pages in pdf file and to notedown count in a seprate excel sheet
Thanks in advance guys

Moderator: DosItHelp
Code: Select all
@echo off
cls
set /p "file_name=File name: "
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v ""
aGerman wrote:@ShadowThief
Your code workes for just the few files that I tested but it may have an issue. FINDSTR does not Support the \s sequence for White Spaces. That means the back slash doesn't have any effect. /Type/Page would be matched as well as /Types/Page while /Type /Page would not.
I'm not familiar with the PDF specification. Hence I don't know if you would ever get into trouble because of that.
Regards
aGerman
Code: Select all
<</Count 8/Type/Pages/Kids[blah blah]>>
ShadowThief wrote:Code: Select all
@echo off
cls
set /p "file_name=File name: "
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v ""
sivasriram wrote:ShadowThief wrote:Code: Select all
@echo off
cls
set /p "file_name=File name: "
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v ""
the code was not working here
it is running fine, but output is not at all appearing...
Code: Select all
@echo off
cls
set /p "file_name=File name: "
echo|set /p=%file_name%,>>pdf_num.csv
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v "">>pdf_num.csv
Code: Select all
@echo off
for %%a in (*.pdf) do (
find "Count " < "%%a"|repl ".*Count ([0-9]*).*" "$1 pages = \q%%a\q" ax
)
pause
Code: Select all
@if (@X)==(@Y) @end /* JScript comment
@echo off
cscript //E:JScript //nologo "%~f0" %*
exit /b 0
@if (@X)==(@Y) @end JScript comment */
var args=WScript.Arguments;
var filename=args.Item(0);
var fSize=0;
var inTag=false;
var tempString="";
var pages="";
function getChars(fPath) {
var ado = WScript.CreateObject("ADODB.Stream");
ado.Type = 2; // adTypeText = 2
ado.CharSet = "iso-8859-1";
ado.Open();
ado.LoadFromFile(fPath);
var fs = new ActiveXObject("Scripting.FileSystemObject");
fSize = (fs.getFile(fPath)).size;
var fBytes = ado.ReadText(fSize);
var fChars=fBytes.split('');
ado.Close();
return fChars;
}
function checkTag(tempString) {
if (tempString.length == 0 ) {
return;
}
if (tempString.toLowerCase().indexOf("/count") == -1) {
return;
}
if (tempString.toLowerCase().indexOf("/type") == -1) {
return;
}
if (tempString.toLowerCase().indexOf("/pages") == -1) {
return;
}
if (tempString.toLowerCase().indexOf("/parent") > -1) {
return;
}
var elements=tempString.split("/");
for (i = 0;i < elements.length;i++) {
if (elements[i].toLowerCase().indexOf("count") > -1) {
pages=elements[i].split(" ")[1];
}
}
}
function getPages(fPath) {
var fChars = getChars(fPath);
for (i=0;i<fSize-1;i++) {
if ( fChars[i] == "<" && fChars[i+1] == "<" ) {
inTag = true;
continue;
}
if (inTag && fChars[i] == "<") {
continue;
}
if ( inTag &&
fChars[i] == ">" &&
fChars[i+1] == ">" ) {
inTag = false;
checkTag(tempString);
if (pages != "" ) {
return;
}
tempString="";
}
if (inTag) {
if (fChars[i] != '\n' && fChars[i] != '\r') {
tempString += fChars[i];
}
}
}
}
getPages(filename);
if (pages == "") {
WScript.Echo("1");
} else {
WScript.Echo(pages);
}
Code: Select all
cscript //E:JScript //nologo "%~f0" %*
Code: Select all
for %%a in (*.pdf) do echo "%%a"&cscript //E:JScript //nologo "%~f0" "%%a"