views:

287

answers:

1

Does anyone know of a server side technology that can print/save a web page to PDF including embedded Flash components?

Essentially I would like simulate client side printing to PDF functionality but on the server to implement a "Download PDF" link but I don't believe HTML to PDF solutions support Flash.

+1  A: 

Maybe ... if you can open a window on the server. Try this: Get SWT (it contains a browser component). Use the browser snippet to make sure it can display Flash (see the FAQ below for details how to make plugins work). If it does, then you can use JavaScript to print:

browser.execute("window.print();");

On Unix, this should be enough. On Windows, you'll have to install a PDF printer driver and use a UI automation tool to press the "OK" button of the print dialog.

See the SWT FAQ for lots of details how to get the browser widget to work in various environments.

If that works, you can try to create the shell but don't open it (so no window pops up on the screen). Printing should work without actually drawing anything on the screen but you'll have to do a bit of experimenting.

I used this technology to create screenshots of all pages of our webapp by pressing a button (open the URL, wait it to load, copy the main drawable, save image to file).

Alternatively, you could use an ActiveX bridge to embed Internet Explorer in a Java app via JDIC. The app can then wait for remote print requests.

[EDIT] Alternatively, if you have a HTML->PDF solution which lacks Flash support, just open the Flash element in the embedded browser. Save a screenshot of the browser widget as an image and modify the HTML to use the image instead of the real Flash (search for the embed tag and replace it with img).

[EDIT2] If SWT doesn't work, have a look at QtJambi (which contains WebKit). Note that QtJambi is currently in the process of being migrated to LGPL. I'm not sure if the Flash plugin works in WebKit, though.

Aaron Digulla
Not sure if this will work but I'll give it a shot and see what happens.
Michael Glenn
It's an insane hack but it worked for me :) Good luck!
Aaron Digulla