I have following code in web aplication
java.awt.Desktop.getDesktop().print(new File(path));
It is working with any problem on desktop aplication. But doens’t in web app. And I need print the file. How to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As Joachim has pointed out, the Java code is running on the server, not the client so you’re not going to be able to use Java to print from a web-app.
What you can use though is JavaScript
window.print()to print the contents of the browser window.Now you’re unlikely to want to print the window contents exactly as it appears in the browser, which is where a print style-sheet comes into play – assuming your page was written to be web-standards compliant (at least when it comes to the use of CSS), you simply write a second style-sheet that controls the appearance of the page when it’s printed as described here.
So in your case, you would need to render the contents of the file into the page the browser is displaying (maybe in a hidden
div) and then the print style-sheet would hide the content displayed in the browser and show the file contents.