Well, counting the words in the document wasn't really the problem, it was getting the document open in the first place.
The PDI functions that ship with the PDF extension of PHP aren't enabled by default, if I remember correctly. I could be wrong, though... The reason I suspect this is the case is because the basic (read: free) version of PDFLib doesn't include the PDI extension.
PHP's PDF extension would still have the functions defined, but they wouldn't actually work unless your version of PDFLib implemented the PDI functions.
I would suggest going through each line in your code to see which function is actually failing... is it pdf_new() or really pdf_open_pdi()?