How can I print a web page on a server?
Posted
by Gavin Schultz
on Stack Overflow
See other posts from Stack Overflow
or by Gavin Schultz
Published on 2010-03-26T06:12:40Z
Indexed on
2010/03/26
6:23 UTC
Read the original article
Hit count: 351
Suppose I develop a web page using the cool Google visualization API, and it does everything the user wants. They can the parameters, look at the graphs, and print the page to get a reasonable-looking report. All good.
Now suppose I want to do the same thing server-side. For example, say we need a set of report generated at a specific time of day, printed to a PDF and emailed to a manager. It's not a user-initiated action, so we don't have a user's browser or their printer. We have a URL that would render the report if we had a browser, and that's it.
Is there a good way to do this server-side? Is this just foolish? Has anyone done anything like that before? Do any of the major browsers have APIs that might provide such functionality?
Keep in mind too that it's not just static HTML; probably javascript will be running first to shift the DOM around.
I know we could implement a whole different reporting engine on the server side to do this, but that will (a) generate reports that look a bit different, and (b) require me to build/maintain two sets of functionality.
Instead, I'd be happy if I could just render the page / pages I want in an invisible server-side browser and print it to a PDF (let's mostly ignore that step - I know any number of PDF printer drivers that could do this).
I don't really want to do it ugly either - i.e. by starting a browser process and then sending keystrokes directly to the window either - that's just bound to fall apart with a slight nudge. The only related question I found had an answer like that.
Any advice appreciated!
© Stack Overflow or respective owner