# How to count number of pages in a PDF?

**URL:** <https://www.ruby-forum.com/t/how-to-count-number-of-pages-in-a-pdf/56650>\
**Category:** Rails\
**Created:** [April 2, 2006, 5:32am UTC](https://www.ruby-forum.com/t/how-to-count-number-of-pages-in-a-pdf/56650 "2006-04-02T05:32:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@cal](https://www.ruby-forum.com/u/cal)\
**Post date:** [April 2, 2006, 5:32am UTC](https://www.ruby-forum.com/t/how-to-count-number-of-pages-in-a-pdf/56650/1 "2006-04-02T05:32:27Z")

</div>

Does any know a simple way to count the number of pages in a PDF file?  
I’m  
using teh RTEX plugin to generate a PDF via pdflatex with a defined  
start page  
number. I want to determine the final page number so I can start the  
next PDF  
in sequence.

Thanks in advance for your help!

-cal

---

<div class="post-metadata">

**Author:** ![cal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f1d935/32.png) [@cal](https://www.ruby-forum.com/u/cal)\
**Post date:** [April 2, 2006, 7:30am UTC](https://www.ruby-forum.com/t/how-to-count-number-of-pages-in-a-pdf/56650/2 "2006-04-02T07:30:39Z")

</div>

I am using pdfbox for that, open source and simple to use if you are  
familiar with java, but comes with the cost of starting a JVM. There is  
also  
a comercial lib called PDFLib, which now has Ruby bindings and which  
works  
very well in general.

Maybe there is an even simpler way, I also would like to know.
