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
sivasriram
Posts: 12
Joined: 30 Aug 2014 10:55

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

#31 Post by sivasriram » 03 Sep 2014 11:06

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

here is it


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
FINDSTR: Cannot open C:\Documents
FINDSTR: Cannot open and
FINDSTR: Cannot open Settings\Prudhvi\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

#32 Post by foxidrive » 03 Sep 2014 11:07

npocmaka's solution worked for these - but is slower. The actual page count reported by Foxit is after the calculated figures.

Code: Select all

"Everything.pdf" 298 (actual 298)
"Philosophy.pdf" 954 (actual 955)
"debris.pdf" 144 (actual 144)
"Men.pdf" 166 (actual 166)
"maker.pdf" 345 (actual 345)
"Dream.pdf" 240 (actual 234)


ShadowThief's solution gave me this:

Code: Select all

Everything.pdf, 0
Philosophy.pdf, 3
debris.pdf, 0
Men.pdf, 0
maker.pdf, 345
Dream.pdf, 731

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

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

#33 Post by foxidrive » 03 Sep 2014 11:16

Squashman wrote:
foxidrive wrote:list of pdf files

That is some interesting reading material.


List removed to protect the innocent. ;)
yeah, though I only read on the internet these days. Used to raid the library regularly before the internet started, for Sci Fi and Horror stories.

Now I see enough Horror stories by reading batch file questions. :)

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

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

#34 Post by penpen » 03 Sep 2014 11:21

I've read (a little bit) into (PDF32000_2008.pdf on http://www.adobe.com/devnet/pdf/pdf_reference.html).

The problems that may occure:
- Literal Strings (Definition: 7.3.4.2 Literal Strings; page 15), and Comments (Definition: 7.2.3 Comments; Page 13)
may contain data, that is similar to the searched one: See examples 1 + 2 in the code block below.
In theory it also could be contained on Object Streams (7.5.7 Object Streams; page 45), but it should be
improbable enough, so i haven't searched for an example.
- if the page tree root node is encapsulated within an indirect object, it may be located within an object stream
(7.3.10 Indirect Objects; page 21)
- as if this wasn't enough... any stream object may be contained in an external file (7.3.8.1 General; page 19)

Code: Select all

% ...
123 0 obj
(
Example1:
A String and no page tree root node.

2 0 obj   % Page tree root node, although it looks like one
<< /Type /Pages
/Kids [4 0 R]
/Count 234
>>
endobj
)
endobj

% Example2: A Comment and no page tree root node. 3 0 obj << /Type /Pages /Kids [6 0 R] /Count 3456 >> endobj

% the real tree root node
4 0 obj
<< /Type /Pages
/Kids [3 0 R]
/Count 1
>>
endobj

% ...

So it is a very hard task to reliably compute and display the number of pages within batch, ...
or in any other programming language:
You have to implement at least the Standard Filters (Table 6 – Standard filters; page 23).

So i think the task should be restricted in some way.

penpen

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

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

#35 Post by npocmaka_ » 03 Sep 2014 14:11

a little bit more here..

Found this : http://www.mombu.com/computer_design/in ... 24838.html

the trick really works with pdf 1.3 and 1.4 - (searches on the third line for /N XXX string )

And this does not work - http://www.electronmedia.in/wp/pdf-page ... avascript/

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

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

#36 Post by penpen » 03 Sep 2014 15:40

npocmaka_ wrote:Found this : http://www.mombu.com/computer_design/in ... 24838.html

the trick really works with pdf 1.3 and 1.4 - (searches on the third line for /N XXX string )
If i see it right, then this trick does not work on the PDF 1.4 "[MS-LCID].pdf" downloadable from:
http://msdn.microsoft.com/en-us/library/cc233965.aspx.
The one linked with "Click here to view this version of the [MS-LCID] PDF. ".

Beside i'm pretty sure that any other (reliable) way would have been mentioned within the Adobe Specification of the PDF format.
So i think these 'tricks' all are basing on (some) optional data (maybe provided by a specific program, that is able to create PDF's).

penpen

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

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

#37 Post by Samir » 11 Feb 2015 15:43

This doesn't bring anything new to finding a pure batch way to counting pdf files, but there's a command line utility called cpdf that has a switch to count the number of pages in a pdf.

It's a third party program, but I'm sure if the goal is to make something batchable, this would help do it. 8)

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

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

#38 Post by ShadowThief » 11 Feb 2015 21:49

Oh hey, I remember this topic. From five months ago.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

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

#39 Post by Samir » 11 Feb 2015 22:19

ShadowThief wrote:Oh hey, I remember this topic. From five months ago.
So did I. And since I found a very batchable third party command line exe that could solve the OP's issue, I thought I'd add it to help someone.

Old threads are gold when they have a solution--whenever that solution comes about.

Post Reply