aspose file tools*
The moose likes Beginning Java and the fly likes [PrintService] Pb while printing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[PrintService] Pb while printing" Watch "[PrintService] Pb while printing" New topic
Author

[PrintService] Pb while printing

Nicolas Daudin
Greenhorn

Joined: Dec 19, 2007
Posts: 12
Hi there
I have a little problem with my Swing application. I'm trying to print a String to my default printer using PrintService, and it does not work, either from my Mac or my PC.

On my Mac i get the following (and yet nothing is printed)


On my PC i get the following (same code, same default printer found):


As you can see, for the Mac, the printer is found, and it is even said that the job has been printed. BUT nothing is printed. Yet my printer works, i can print something from Word for example.
For the PC i don't understand why the flavor is wrong...

So thanks for any precious help!

Nico.
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
can you post the code that is doing the printing...


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

Originally posted by Nicolas Daudin:





What DocFlavour you are using to print.
Have you tried

DocFlavor.INPUT_STREAM.AUTOSENSE;.If not make you code to include



then check it.
Nicolas Daudin
Greenhorn

Joined: Dec 19, 2007
Posts: 12
Hi,
My code doing the printing is the following:
Ryan Doe
Greenhorn

Joined: Jan 09, 2008
Posts: 1
Hi,
I also have the same problem. There's no error in my program but the printer did not print my document.. please help me.. here is my code:

PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
pras.add(MediaSizeName.ISO_A4);

String username = "ryanadmin";
String password = "java123";

String input = "Username: " + username + "\n" + "Password: " + password;
//I just want to print a string..

InputStream is = new ByteArrayInputStream(input.getBytes());
is = new BufferedInputStream(is);

DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
DocAttributeSet das = new HashDocAttributeSet();

PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Printer:" +printService);
PrintService[] services =PrintServiceLookup.lookupPrintServices(flavor,das);

DocFlavor[] flavors = printService.getSupportedDocFlavors();
for (int i = 0; i < flavors.length; i++) {
System.out.println(flavors[i].toString());
}
DocPrintJob job = printService.createPrintJob();

PrintJobListener pjlistener =new PrintJobAdapter(){

public void printDataTransferCompleted(PrintJobEvent e){
System.out.println("Document sent to printer.");
}

public void printJobCompleted(PrintJobEvent e){
System.out.println("Document was successfully printed.");
}

public void printJobFailed(PrintJobEvent e){
System.out.println("Document failed to print.");
}

public void printJobNoMoreEvents(PrintJobEvent e){
System.out.println("No more print events.");
}

public void printJobRequiresAttention(PrintJobEvent e){
System.out.println("Printer requires attention.");
}
};

job.addPrintJobListener(pjlistener);

Doc doc = new jSimpleDoc(bis, flavor, null);
job.print(doc, pras);


Thanks.. Any comment will be greatly appreciated..
Nicolas Daudin
Greenhorn

Joined: Dec 19, 2007
Posts: 12
Hey
I'm still working on my problem, so as soon as i find an answer i'll let you know (as a matter of fact i havent had time yet to try what someone suggested me, i.e. put DocFlavor flavor=DocFlavor.INPUT_STREAM.AUTOSENSE)...
About your problem, do you have any log regarding your listners? do they print something?
Nicolas Daudin
Greenhorn

Joined: Dec 19, 2007
Posts: 12
As for me, i still didn't have found the solution...
Ryan, did you find something?
Nicolas Daudin
Greenhorn

Joined: Dec 19, 2007
Posts: 12
OK i'm moving forward a bit but my config is not helping. I'm usually developing using my Mac but all the users are under PC.
So, seeing all my problems i decided to try this as well on PC. And with the same test code


I get with my PC:


And with my Mac:
Nicolas Daudin
Greenhorn

Joined: Dec 19, 2007
Posts: 12
Originally posted by Balasubramanian Chandrasekaran:


What DocFlavour you are using to print.
Have you tried

DocFlavor.INPUT_STREAM.AUTOSENSE;.If not make you code to include



then check it.


I tried DocFlavor.INPUT_STREAM.AUTOSENSE, but my problem is that my special characters ('�' for example) are not taken into account...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [PrintService] Pb while printing
 
Similar Threads
PrintService problem
CommunicationException
Windows - Java - Printer - PDF - Status Issue.
WAMP/Java/MysqlConnector Issue
How to put JDBC driver in applet jar?