Egreg has provided a way to obtain the page count of a PDF using pdfTeX to extract this information from the PDF itself, but it's worth adding to this why a simple 'core TeX' approach does not work.
You may know that TeX uses \count0 to provide information about which page is being output, and that this is used for adding page number information to printed pages. However, TeX does not use this to track the 'absolute page from start of document'. You can see that with a short demo file
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\count0 10 %
\lipsum
\end{document}
This produces two pages of output, but as I've set the first page as '10' they are listed as pages 10 and 11. TeX writes the value of \count0 to the log when a page is shipped out (in square brackets), and it shows that as far as TeX is concerned these are indeed pages ten and eleven:
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012)
\write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2012-05-30, ngerman-x-2012-05-30, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, friulan, galician, german, ngerman, swissgerman, monogreek, greek, h
ungarian, icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, ma
rathi, oriya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian,
kurmanji, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk,
polish, portuguese, romanian, romansh, russian, sanskrit, serbian, serbianc, s
lovak, slovenian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian,
welsh, loaded.
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2012/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2012/texmf-dist/tex/latex/lipsum/lipsum.sty) (./test.aux)
[10{/usr/local/texlive/2012/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
[11] (./test.aux) )</usr/local/texlive/2012/texmf-dist/fonts/type1/public/amsfo
nts/cm/cmr10.pfb>
Output written on test.pdf (2 pages, 22281 bytes).
SyncTeX written on test.synctex.gz.
Transcript written on test.log.
Indeed, it is also possible to have the same page number twice
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum
\count0 1 %
\lipsum
\end{document}
Thus \count0 is only reliable if you can be certain that nothing has messed about with it, which in general is not the case.
texdoc pdftex– AlexG Nov 15 '12 at 13:18