Is there a way to count the number of pages in a PDF?

Is there a way to count the number of pages in a PDF to use as a trigger condition?
Example: If PDF is smaller than 2 pages then complete actions?
I've tried using file size, but it's not reliable enough as page content can make a big difference to file size.
Thanks.
Example: If PDF is smaller than 2 pages then complete actions?
I've tried using file size, but it's not reliable enough as page content can make a big difference to file size.
Thanks.