Ghostscript pdf text extraction

I need to extract text from online pdf documents. How can I use Ghostscript in a php script for example? Any other suggestions?