Working code to count pages in a pdf