page count of a pdf file

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
sonusdream

page count of a pdf file

Post by sonusdream » 2006-11-02T20:14:52-07:00

i was wondering if there is a way to check for the number of pages of a pdf file without extracting the pages and counting the number of jpg files it generated.


thanks in advance


regards,
sonus

User avatar
magick
Site Admin
Posts: 11015
Joined: 2003-05-31T11:32:55-07:00

Post by magick » 2006-11-02T20:40:31-07:00

To get the number of pages in a PDF document, use this command:
  • identify -format %n image.pdf

ddodson001
Posts: 1
Joined: 2019-01-15T09:29:39-07:00
Authentication code: 1152

Re: page count of a pdf file

Post by ddodson001 » 2019-01-15T09:36:47-07:00

I just tried this and was happy to see the number of pages, however, it was a repeating string of the number of pages.

Code: Select all

$ identify -format %n test.pdf
16161616161616161616161616161616
Any idea how I get this to return just '16'?

Thank you,
David

bratpit
Posts: 11
Joined: 2018-09-16T00:20:21-07:00
Authentication code: 1152

Re: page count of a pdf file

Post by bratpit » 2019-01-15T09:41:44-07:00

pdfinfo sample.pdf | grep -a Pages | cut -d : -f 2

snibgo
Posts: 11916
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: page count of a pdf file

Post by snibgo » 2019-01-15T10:13:35-07:00

Or:

Code: Select all

identify -format %n\n in.pdf |head -n1
snibgo's IM pages: im.snibgo.com

User avatar
GeeMack
Posts: 709
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: page count of a pdf file

Post by GeeMack » 2019-01-15T12:40:02-07:00

ddodson001 wrote:
2019-01-15T09:36:47-07:00
Any idea how I get this to return just '16'?
Try something like this...

Code: Select all

convert document.pdf -set option:totpages %[n] -delete 1--1 -format "%[totpages]\n" info:

Post Reply