开发者

How to show and deploy a PDF document from Java using WebStart

I want to show a PDF document from a Java (Swing) application in a system independent manner (provided that a PDF viewer is properly installed on the target system).

Also I'开发者_StackOverflow社区d like to deploy this PDF document using Java WebStart.

Could you please tell me the "standard" way to achieve this? (I confess, I'm to lazy/busy to look up the details ...) Thanks!


I assume you mean you want to deploy the PDF along with the Java Web Start application? If so, you simply need to package the PDF(s) with your webstart application. When your application downloads and runs, the PDFs will have come too, and your code can use the getClass().getResource("/where/is/my.pdf") type of lookup to locate the PDF and then operate on it for display. You might also need to get your code to read the PDF out of the resources and save it in a temp file (File.createTempFile()) so that the PDF viewer can see it.

rough idea:

  // Find the PDF in the Webstart App download
  InputStream in = getClass().getResourceAsStream("/where/is/my.pdf");

  // create a temp file to copy the pdf to
  File tmpFile = File.createTempFile("my", "pdf");
  OutputStream out = new FileOutputStream(tmpFile);

  // stream the file from in to out ... heaps of examples on the net for doing this ("copy files")

  // display the file
  Desktop.getDesktop().open(tmpFile);

  // ideally clean the tmp file up at some point.


You can use the Java 6 Desktop system and Desktop.open() to open the associated desktop application for your document (in this case, a PDF file).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜