How to execute AJAX call with PhantomJSDriver?
Please have a look on this question. This might solve your problem.
How to download a csv file using PhantomJS
You can make AJAX call to download and encode your file, then you can return this content back.