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

Posted on 2009-12-21
Medium Priority
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

Gurvinder Pal Singh earned 400 total points
ID: 26102342
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

objects earned 400 total points
ID: 26102478

Assisted Solution

deeppra earned 400 total points
ID: 26113437
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

839 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