The only reliable way to do page counting in the face of PostScript, PCL, and other mystical printer job languages is to query the printer and get the current value of a hardware page counter. Unfortunately, this may not be a trivial matter. The page counter may not be updated in real time. This means that you may need to wait a couple of seconds until you are sure that the pages have been recorded. Usually this occurs when the pages leave the print engine and are put in the output tray.
Printers do job batching, and when they report job completion the job is still being printed.
Some printers report impressions , i.e.- sides of pages printed, rather than pages. Some printers simply lack page reporting. Given these problems, it is more than reasonable to reconsider the need for accounting, or to work closely with the printer vendor to understand the interactions of print jobs and reporting of page counts.