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 .
LVL 1
mansur_mcaAsked:
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) {
      ioe.printStackTrace();
    }

See the following link to print on a network printer
http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/wwhelp/wwhimpl/common/html/wwhelp.htm?context=sdkHelp&file=000371.html
http://www.exampledepot.com/egs/javax.print/DiscoverAll.html?l=rel

Thanks
0
 
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,
http://support.microsoft.com/kb/314499
0
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.