views:

35

answers:

3

I have a java applet that creates a JPEG file. I want to pass that file to a Javascript where it can display and print it. The only way I can think of doing this is to save the jpeg to a temporary storage area on the user's computer and then pass the path of the file to the javascript which picks it up and displays it. This raises a two questions:

  1. Where should the applet store the file. If you suggest the temporary internet files folder, then how do I find that path to that folder?

  2. Is there a better way to do this? Can I pass the JPEG directly from java to javascript without first writing out to a disk?

Thank you in advance for your help.

A: 

Can't you just have an applet that displays the picture and prints it?

Helgi
+1  A: 
  1. To store file on users's machine your applete should be signed, and user should give necessary permissions to your applet (through special dialog window which is shown automatically).

  2. Read this article about modifying DOM from applet

  3. Another approach is to save your image on the server (pass it from your applet to the server) and then reload page (or use Ajax, but in this case you probably have to make ajax calls every few seconds to check if the image is available on the server).

Roman
A: 

I don't think it'd be possible to do this in IE before IE8 (and it's wimpy even in IE8), but in other browsers your applet could make the image data available to Javascript (please don't say, "a Javascript"; it's like saying, "a FORTRAN" or "a Java") and then from Javascript you could create an <img> tag with a "data URI". See this reference: http://en.wikipedia.org/wiki/Data_URI_scheme

Pointy