在java web应用程序中如何从客户端打印服务器文件 [英] In java web application how to print server file from client side

查看:228
本文介绍了在java web应用程序中如何从客户端打印服务器文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java web应用程序中需要从服务器中选择文件并打印到本地打印机。如何做到这一点

In the java web application need to select the file from server and print to the local printer. how it can be done

提前致谢

推荐答案

这是怎么回事每当您需要最少的用户交互时(即只需单击链接然后执行打印魔术),它就会变得棘手,而且还取决于相关文件的类型。如果它是例如 .doc 文件,那么您基本上需要将其下载到客户端环境并在默认的关联应用程序中打开它(在本例中为MS Word)然后让应用程序执行print命令。您无法从服务器端执行此操作。

That's going to be tricky whenever you require a minimum of user interaction (i.e. just click the link and then do the print magic) and it also depends on the type of the file in question. If it is for example a .doc file, then you would basically need to download it to the client environment and open it in the default associated application (MS Word in this case) and then let the application execute the print command. You can't do this from the server side on.

最好的办法是创建一个 Applet 反过来显示文件树,在客户端交互时将文件下载到本地磁盘文件系统并使用 桌面#print() 打印它。例如,

Your best bet is to create an Applet which in turn displays the file tree, downloads the file to the local disk file system on client interaction and makes use of Desktop#print() to print it. E.g.

File file = new File("/temp/file.doc");
// Read file from server using URLConnection, write it to this file and then do:
Desktop.print(file);

但如果是普通的文字文件,如 text / html text / xml ,等等,然后你可以使用Javascript将文件加载到一些< div> < iframe> 元素,然后执行 window.print ()方法,如有必要,还有 CSS媒体规则

But if it are for example plain text files such as text/html, text/xml, etcetera, then you can make use Javascript to load the file into some <div> or <iframe> element and then execute the window.print() method on it, if necessary along with a CSS media rule.

这篇关于在java web应用程序中如何从客户端打印服务器文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆