Art
Art

Reputation: 237

Call phantomjs from webpage

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?

Upvotes: 0

Views: 1052

Answers (2)

pguardiario
pguardiario

Reputation: 54984

You can call phantomjs from the server by shelling out to it. In most languages that will look like:

`phantomjs myscript.js`

Upvotes: 0

svenhornberg
svenhornberg

Reputation: 15756

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.

Upvotes: 1

Related Questions