Page 1 of 1

PDF page count

Posted: 2015-09-30T08:12:09-07:00
by marky
Dear Gurus,

I'm trying to use the command I've read a few times but cannot get it to work properly. I wish to count the pages in a PDF. I have tried:

identify -format %n image.pdf

However, if it is 2 pages I get 22
If it is 6 I get 666666
If it is 55 I get 555555555555555555555555555555..........(you get the idea!)

Please can I get some help?

Thanks in advance.

Re: PDF page count

Posted: 2015-09-30T08:50:20-07:00
by snibgo

Re: PDF page count

Posted: 2015-09-30T09:33:57-07:00
by marky
Thanks. I'm not the greatest coder but I put a \n, converted it to a string, searched for the first space and split the string and converted back to an integer - sure someone can do it easier but it does now work!!!

$page_count_raw=$(identify -ping -format %n\n c:\mark\temp\count\Test.pdf)
$page_count_string_all = [String]$page_count_raw
$space_index = $page_count_string_all.IndexOf(" ")
$page_count_string = $page_count_string_all.Substring(0,$space_index)
$page_count = [int]$page_count_string