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

Posted on 2009-12-21
Last Modified: 2012-05-08
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 .
Question by:mansur_mca
    LVL 40

    Accepted Solution

    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

    LVL 92

    Assisted Solution

    LVL 5

    Assisted Solution

    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,

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now