Call phantomjs from webpage

时间:2015-09-14 15:18:28

标签: javascript phantomjs

I have some HTML reports generated by Classic ASP and I need them converted to PDF. Searching for a solution I found out phantomJS, which has 'rasterize.js', a functionality that would take the HTML and output it as PDF.

The problem is that I can´t figure out how to call phantomJS from my original/current webpage.

The idea I had in mind is, my current webpage calls phatomjs sending its HTML content then phantomjs would call rasterize.js and output the PDF to the server, then I would get the name of the recently created PDF and serve it back to the client.

Is there a way this could be done?

2 个答案:

答案 0 :(得分:1)

Phantomjs is not the made for running in the browser as far as I know.

You have different options for this:

  1. use a libaray like https://parall.ax/products/jspdf which has a fromHTML method to render html content to pdf
  2. Send your html content to a remote server which renders a PDF and send it back to you, a friend of mine contributes to this https://github.com/piobyte/flamingo. It it a server which does this.
  3. Use some sort of messaging (e.g. websocket) to inform a remote server to render your page and give the user a download link.

答案 1 :(得分:0)

你可以通过shell来调用服务器上的phantomjs。 在大多数语言中看起来像:

`phantomjs myscript.js`