PDF page count

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
marky
Posts: 5
Joined: 2015-09-30T08:07:51-07:00
Authentication code: 1151

PDF page count

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PDF page count

Post by snibgo »

snibgo's IM pages: im.snibgo.com
marky
Posts: 5
Joined: 2015-09-30T08:07:51-07:00
Authentication code: 1151

Re: PDF page count

Post 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
Post Reply