• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[PrintService] Pb while printing

 
Nicolas Daudin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 184
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the code that is doing the printing...
 
Balasubramanian Chandrasekaran
Ranch Hand
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
My code doing the printing is the following:
 
Ryan Doe
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for me, i still didn't have found the solution...
Ryan, did you find something?
 
Nicolas Daudin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic