This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes JAVA API ( JPS )  For Printing out in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JAVA API ( JPS )  For Printing out in JAVA" Watch "JAVA API ( JPS )  For Printing out in JAVA" New topic
Author

JAVA API ( JPS ) For Printing out in JAVA

Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

Dear All,
I have an requirement to print an out file using JAVA API ( JPS ) in windows environment. I should be able to control parameters like
page size , page width , page break while printing the out file. I would appreciate some one letting me know the appropriate JAVA API
to be used. Some of the resource material I got from net

http://java.sun.com/j2se/1.4.2/pdf/JPS_PDF.pdf

Regards,
Anil
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
The examples in that PDF demonstrate how to use various attributes; what else are you looking for? Check out the classes in the javax.print.attribute.standard package for what else is possible.


Ping & DNS - my free Android networking tools app
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34


I need to search for the print services capable of printing the specified attribute. This search is to performed at the client and not server. How do I proceed further ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
I need to search for the print services capable of printing the specified attribute.

And there's a code example in that PDF that demonstrates how to do that; it's called "PrintPS".

This search is to performed at the client and not server.

I don't understand what you mean by client and server in this context.
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

Let us assume that we have 2 PC configured in a LAN environment . One among them is say server and other is client.
When I search for the services capable of printing , this search is performed at the server and not at client.
Printer is configured at client and not at server. So how do I Locate print services installed at the client ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
If you want to discover printers on the "client", why would you run the code on the "server"? I'm putting those in quotes because I'm still not sure what those designations have to do with the problem.

Is this maybe a web app, and you want to print something on a printer connected to the client? If so, that's only possible if the printer is set up as a network printer so it's visible to the server.
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

It looks like I have not been able to explain my problem clearly .
My application server runs on Linux OS. Printing of the reports is done by executing shell script on the text file. The general syntax used is ssh root@client_ip_adress script file name text file name. Execution of shell script is not possible if the client accesses the application from windows. This is because executing script file is not possible in windows environment. I want to avoid the use of script and directly send the text file to the printer port for printing. Each client will have its own printer , none among them will be using shared printer. For this I had thought of using JPS api.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
I'm still not sure on which machine the code that should do the printing runs; I'm guessing the app server - is that correct? If so, then this approach won't work because the server does not have access to client-side printers.
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

The execution of print job is at the client . That is why when the app sever is accessed from windows environment , printing can not be done. This is because script file can not be executed in windows environment. To avoid all this I was thinking of using JPS api .
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

Let me know if there is way to print an text file generated in app server to local machine connected to the printer. Accessing the out file from local machine is not a problem . But I am not able to populate list of print service installed in local machine. As discussed the code written is executed at the server , so it populates the list of print services running on the server and not the client.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
As I've said before, code running on the server can't access printers installed on the client, so you'll need to find a way to transfer the file to the client where it can be printed in various ways.
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

K thanks for your reply . I will try to work out a solution.
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

I have made use of a signed applet to access client resource ( Local printer installed ) . Print code works fine . Currently it is only possible to track the print job status. For this we can make use of methods ( printJobCompleted , printJobFailed ..... ) defined in PrintJobListener interface . How should one check the status ( on line and off line ) of the printer. Do we have any third part api to check the status of the printer ?.

PS : I am not sure If I should be opening up a new the thread for this issue but as the issue is connected to the earlier issues faced by me , I have continued the discussion here.
Anil Kumar
Ranch Hand

Joined: Nov 16, 2008
Posts: 34

Anil Kumar wrote:I have made use of a signed applet to access client resource ( Local printer installed ) . Print code works fine . Currently it is only possible to track the print job status. For this we can make use of methods ( printJobCompleted , printJobFailed ..... ) defined in PrintJobListener interface . How should one check the status ( on line and off line ) of the printer. Do we have any third part api to check the status of the printer ?.

PS : I am not sure If I should be opening up a new the thread for this issue but as the issue is connected to the earlier issues faced by me , I have continued the discussion here.



Added the following comments on 29/04/10

Currently no Java api provides support to check the status of the printer. Thanks Ulf Dittmer for your timely help. It can be done only through the use of script.
 
 
subject: JAVA API ( JPS ) For Printing out in JAVA
 
Similar Threads
Print a document using java API
Printing in Java
Pring API suggestion needed
Java Print service
Servlet/JSP engine