Java/j2ee - Sending print request (without having preview) to default printer for documents stored in local PC.

Is there any simplest way of achieving this requirement in Java/j2ee just by giving the path of file location stored, as input to the program.

please advice .
Who is Participating?
Gurvinder Pal SinghConnect With a Mentor Commented:
If i have understood your requirement correctly, you want to print a file on server from client machine on client's printer.
Yes why not.

Follow these steps
1) Transfer the contents of file to the local system. You can fetch the serialized File object to do so.
2) create a local temporary file, say abc.txt (or which ever format it is).
3) Print it on a local printer using the following (jdk6)
try {
      Desktop desktop = null;
      if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();

       desktop.print(new File("c:\\a.txt"));
    } catch (IOException ioe) {

See the following link to print on a network printer

deeppraConnect With a Mentor Commented:
If its a standalone java application you can open the outputstream in LPT1 port which is the default port for printer and write the content to the stream, in this case it wont ask for any print dialog or anything directly it goes to the printer and the printer starts printing the content.

Please refer the below link to add a default printer,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.