I've a signed applet that retrieves a PDF document from a web service, then stores it on a temp folder, and opens it on Adobe Reader. I would like to avoid storing the file locally, but I really don't know how to achieve it (I'm a newbie with Java applets).
If it were a web application (i.e. a simple servlet), I could just write the PDF content over the ServletResponse; then the browser would store it on its temporary folder, and open it with Adobe Reader (or whatever application is associated with the MIME type).
Is there a similar way to do this... on a Java applet?
This is my code so far:
public class MyListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
// Retrieve the document contents
byte[] content = webService.getPdfDocument(...);
// Write to file
File f = new File("my-document-filename.pdf");
FileOutputStream fos = new FileOutputStream(f);
fos.write(content);
fos.close();
// Open the file
Desktop.getDesktop().open(new File("my-document-filename.pdf"));
}
}
Any alternative to Desktop.open(File), allowing me to pass a byte[] instead of a File?
Desktop.open. It's a perfectly valid way of doing things.