简体   繁体   中英

Triggering a web page print from server side

This question might be very basic. Till now I thought a command to print a webpage can only be initiated at the client side.

(window.print when using javascript)

But I came across http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/ which states about printing using Java. I think this seems to be related to some desktop client and the same may not be possible in a web client. Can anyone confirm and explain this?

You can't execute server side code on the client, so the only way to do it in browser is through javascript or using plugins/flash/java applets.

You could print using java, but for that java needs to run on the client.

A website can ask the browser to open its print dialog (Google Maps does this on the "print directions" page, for example), but it can't actually force the browser to print anything. (If it could, you can be sure that advertisers would use it to print ads on your printer.)

A Java application running locally with sufficient permissions can print, just like any other desktop application. That has nothing to do with web pages.

Don't confuse Java and JavaScript. When trying to use Java within a browser, you'd have to look into using applets. A Java applet could definitely be used to do the kind of work you'd normally have a rich client do from within a browser.

Java applets could also receive events sent out from a server via sockets or some other mechanism, although I'm not certain if security constraints would allow it. Also seems a bit of a roundabout way to do things.

Remember that web browsing is a client-side-driven affair. There's some push models in certain infrastructures (I believe it's possible using JavaServer Faces). But those are probably just a sort of polling mechanism initiated by the client that is abstracted away to look like a server-side push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM