Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Printing API - Unable to print on HP LaserJet

807580Jul 7 2010
Hi,

I'm trying to use Java's printing API to print a PDF file onto a network/local printer.
My code works fine when I try printing onto Canon printers but the behavior is erratic on HP LaserJet printers.

I've tried using two different models of HP LaserJet (4050 Series and 1020 Series )
1. On HP LaserJet 4050 Series PS the print job is processed, but the printer outputs junk/ascii characters instead of the actual pdf
2. On HP LaserJet 1020 Series the print job reaches the queue but stays there indefinitely with the status message 'Printing'.
After this the only way to bring the printer back alive is to shut it down and restart it again.

In both these cases printing from any other application works fine, I run into these issues while using the printing API.
Here's a code snippet that demonstrates the way my client code is written.
  PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
  pras.add(new Copies(1));
  pras.add(MediaSizeName.ISO_A4);

  DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;  
  ByteArrayInputStream bytesinputStream =  new ByteArrayInputStream(myPDFfileContent);

  //'printJob' was obtained by iterating over PrintServiceLookup.lookupPrintServices(null, pras);
  DocPrintJob job = printJob.getPrintService().createPrintJob(); 
  doc = new SimpleDoc(bytesinputStream, flavor, new HashDocAttributeSet());
  job.print(doc, pras);
I'm hoping that someone has experienced this issue before and can help me with this..
Thank you....
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 4 2010
Added on Jul 7 2010
0 comments
448 views