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 »

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: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

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 »

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: 17
Joined: 2018-09-16T00:20:21-07:00
Authentication code: 1152

Re: page count of a pdf file

Post by bratpit »

pdfinfo sample.pdf | grep -a Pages | cut -d : -f 2
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: page count of a pdf file

Post by snibgo »

Or:

Code: Select all

identify -format %n\n in.pdf |head -n1
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
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 »

ddodson001 wrote: 2019-01-15T09:36:47-07:00Any 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