Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Print Service API!!!(File not printed)

 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,
I am using java print service API, for printing generated PDF files, thorugh system's default printer (WinXP OS-system). Now, every time I run the app.,the printer only prints "PDF file not printed.128 MB of memory is reqd. to enable direct PDF printing". If any of you have come across this problem, and has any solution, please pass it onto me.

here is my code snippet
-------------------------------------------
/** "out" refers to ByteOutputStreamArray object,
* which is popolated during PDF generation through XSLT
*/

DocFlavor psFlavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
System.out.println("Step 6 is done");
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(2));
System.out.println("Step 7 is done");
PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Step 8 is done");
if (pservice != null) {
System.out.println("Printer name=>"+pservice.getName());
DocPrintJob pj = pservice.createPrintJob();
System.out.println("Step 9 is done");
try {
if(out != null){
Doc doc = new SimpleDoc(out.toByteArray(), psFlavor, null);
System.out.println("Step 10 is done");
pj.print(doc, null);
System.out.println("Step 11 is done=>document is sent to Printer");
}
else{
System.out.println("The ByteArrayOutputStream is NULL");
}
}
catch (PrintException e) {
System.out.println("Step 12A is reached");
e.printStackTrace();
}
catch (Exception ex){
System.out.println("Step 12B is reached");
ex.printStackTrace();
}
}
else{
System.out.println("No printer service is found!!!");
}
--------------------------------------------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic