how to calculate count of no.of pages in pdf file-batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: how to calculate count of no.of pages in pdf file-batch

#16 Post by npocmaka_ » 03 Sep 2014 08:35

damn....
Shall check for other way to count the pages.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to calculate count of no.of pages in pdf file-batch

#17 Post by foxidrive » 03 Sep 2014 08:59

The PDf was Created by QuarkXPress(R) 9.3

Maybe it's non-standard.

sivasriram
Posts: 12
Joined: 30 Aug 2014 10:55

Re: how to calculate count of no.of pages in pdf file-batch

#18 Post by sivasriram » 03 Sep 2014 09:15

ShadowThief wrote:
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...

Oh yeah, you wanted it output to a file, didn't you? Sorry about that...

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



the above mentioned code is working fine but the csv file is generating count = 0

i m just replaing file name=22.pdf in the code.

am i doing correct please guide me


here is what m doing


set /p "22=22: "
22: echo|set /p=%file_name%,>>pdf_num.csv
findstr /R /C:"/Type\s*/Page[^s]" "%22.pdf%"|find /c /v "">>pdf_num.txt
FINDSTR: Cannot open %22.pdf%

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: how to calculate count of no.of pages in pdf file-batch

#19 Post by ShadowThief » 03 Sep 2014 09:51

You just went through the code and replaced every instance of the string "file name" or "file_name" with 22.pdf, of course it's not going to work; you broke the code!

What the original code did was ask the user to type in the name of the file to get the page numbers for. You would have had to enter something like C:\Users\Joe\Documents\report.pdf.

if you want to store the file name in the code, you'd need something like

Code: Select all

@echo off
cls

set file_name=22.pdf
echo|set /p=%file_name%,>>pdf_num.csv
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v "">>pdf_num.csv

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: how to calculate count of no.of pages in pdf file-batch

#20 Post by npocmaka_ » 03 Sep 2014 09:51

foxidrive wrote:The PDf was Created by QuarkXPress(R) 9.3

Maybe it's non-standard.


rather images are counted for pages where there are no pages.

I suppose the string "/Image/Type" or "/type/image" can be found around 44 times?

sivasriram
Posts: 12
Joined: 30 Aug 2014 10:55

Re: how to calculate count of no.of pages in pdf file-batch

#21 Post by sivasriram » 03 Sep 2014 10:20

ShadowThief wrote:You just went through the code and replaced every instance of the string "file name" or "file_name" with 22.pdf, of course it's not going to work; you broke the code!

What the original code did was ask the user to type in the name of the file to get the page numbers for. You would have had to enter something like C:\Users\Joe\Documents\report.pdf.

if you want to store the file name in the code, you'd need something like

Code: Select all

@echo off
cls

set file_name=22.pdf
echo|set /p=%file_name%,>>pdf_num.csv
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v "">>pdf_num.csv



this is what i tried mate


@echo off
cls

cd desktop\12

set file_name=22.pdf
echo|set /p=%file_name%,>>pdf_num.txt
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v "">>pdf_num.txt

and output is something like this


22.pdf, 0

the pdf contains 14 pages but count i m getting is 0 ? :(

plz help

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: how to calculate count of no.of pages in pdf file-batch

#22 Post by ShadowThief » 03 Sep 2014 10:32

You will have to put the full path of the file if the batch file and the pdf aren't in the same folder.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to calculate count of no.of pages in pdf file-batch

#23 Post by foxidrive » 03 Sep 2014 10:38

npocmaka_ wrote:rather images are counted for pages where there are no pages.

I suppose the string "/Image/Type" or "/type/image" can be found around 44 times?


Yes, it has "/Image/Type/" 44 times, I think.

sivasriram
Posts: 12
Joined: 30 Aug 2014 10:55

Re: how to calculate count of no.of pages in pdf file-batch

#24 Post by sivasriram » 03 Sep 2014 10:40

ShadowThief wrote:You will have to put the full path of the file if the batch file and the pdf aren't in the same folder.


hey shadow see man my folder 12 containsa pdf file named 22.pdf(which is in desktop) i m running code through command prompt if it worked i would do a batch file, but the output is printing 0 every time mate .

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: how to calculate count of no.of pages in pdf file-batch

#25 Post by ShadowThief » 03 Sep 2014 10:44

sivasriram wrote:
ShadowThief wrote:You will have to put the full path of the file if the batch file and the pdf aren't in the same folder.


hey shadow see man my folder 12 containsa pdf file named 22.pdf(which is in desktop) i m running code through command prompt if it worked i would do a batch file, but the output is printing 0 every time mate .

And when you run the script and it asks for a file are you entering C:\Users\<whatever_your_username_is>\Desktop\12\22.pdf ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: how to calculate count of no.of pages in pdf file-batch

#26 Post by foxidrive » 03 Sep 2014 10:49

ShadowThief wrote:And when you run the script


It does return 0 for several files and the number for some others.

sivasriram
Posts: 12
Joined: 30 Aug 2014 10:55

Re: how to calculate count of no.of pages in pdf file-batch

#27 Post by sivasriram » 03 Sep 2014 10:51

ShadowThief wrote:
sivasriram wrote:
ShadowThief wrote:You will have to put the full path of the file if the batch file and the pdf aren't in the same folder.


hey shadow see man my folder 12 containsa pdf file named 22.pdf(which is in desktop) i m running code through command prompt if it worked i would do a batch file, but the output is printing 0 every time mate .

And when you run the script and it asks for a file are you entering C:\Users\<whatever_your_username_is>\Desktop\12\22.pdf ?

this is what i tried now


@echo off
cls
set file_name=C:\Documents and Settings\Prudhvi\Desktop\12\22.pdf
echo|set /p=%file_name%,>>pdf_num.txt



findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v "">>pdf_num.txt



echo|set /p=%file_name%,>>pdf_num.txt

no output nothing this time , even txt file not created in this case

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: how to calculate count of no.of pages in pdf file-batch

#28 Post by Squashman » 03 Sep 2014 10:55

Seems to work for me.

Code: Select all

C:\BatchFiles\PDFCount>dir /a-d /b
pdfcount.bat
ThreePageTest.pdf

C:\BatchFiles\PDFCount>pdfcount.bat
File name: ThreePageTest.pdf

C:\BatchFiles\PDFCount>dir /a-d /b
pdfcount.bat
pdf_num.csv
ThreePageTest.pdf

C:\BatchFiles\PDFCount>type pdf_num.csv
ThreePageTest.pdf, 3

C:\BatchFiles\PDFCount>

ShadowThief
Expert
Posts: 1167
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: how to calculate count of no.of pages in pdf file-batch

#29 Post by ShadowThief » 03 Sep 2014 10:58

sivasriram wrote:no output nothing this time , even txt file not created in this case

Try this. If the path has spaces in it, the whole thing needs to be surrounded by double quotes.

Code: Select all

@echo off
cls
set file_name="C:\Documents and Settings\Prudhvi\Desktop\12\22.pdf"
echo|set /p=%file_name%,>>pdf_num.txt
findstr /R /C:"/Type\s*/Page[^s]" "%file_name%"|find /c /v "">>pdf_num.txt

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: how to calculate count of no.of pages in pdf file-batch

#30 Post by Squashman » 03 Sep 2014 11:03

foxidrive wrote:list of pdf files

That is some interesting reading material.

Post Reply