[英]In java web application how to print server file from client side
In the java web application need to select the file from server and print to the local printer. 在java Web应用程序中需要从服务器中选择文件并打印到本地打印机。 how it can be done
怎么做
Thanks in advance 提前致谢
You will need an applet
, flash
, silverlight
, javafx
- ie an embedded app. 你需要一个
applet
, flash
, silverlight
, javafx
即一个嵌入式应用程序。 There: 那里:
URL.openConnection()
), obtaining the returned bytes and forming an in-memory document URL.openConnection()
)从服务器下载文件,获取返回的字节并形成内存中的文档 (I'm not aware whether the same flow can't be achieved with javascript as well) (我不知道javascript是否也无法实现相同的流程)
That's going to be tricky whenever you require a minimum of user interaction (ie 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. 如果它是例如
.doc
文件,那么您基本上需要将其下载到客户端环境并在默认的关联应用程序(在本例中为MS Word)中打开它,然后让应用程序执行print命令。 You can't do this from the server side on. 您无法从服务器端执行此操作。
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. 最好的办法是创建一个Applet ,然后再显示文件树,在客户端交互时将文件下载到本地磁盘文件系统,并使用
Desktop#print()
打印它。 Eg 例如
File file = new File("/temp/file.doc");
// Read file from server using URLConnection, write it to this file and then do:
Desktop.print(file);
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 . 但是如果它是纯
text
文件,例如text/html
, text/xml
等,那么你可以使用Javascript将文件加载到某些<div>
或<iframe>
元素中,然后执行window.print()
方法,如果有必要,还有CSS媒体规则 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.