• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble Printing with java 1.4!

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Below is my code (it's short) and the output/error I get. Any ideas wtf is going on???

CODE:
public void print() throws PrinterException {
PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(this, this.pageFormat);
PrintRequestAttributeSet pset = new HashPrintRequestAttributeSet();
pset.add(new PrinterResolution(760, 1110, ResolutionSyntax.DPI));
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
DocAttributeSet aset = new HashDocAttributeSet();
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, null);
for (int i = 0; i < pservices.length; i++) {
System.out.println(i + ": " + pservices[i].getName() + " |||| "
+ pservices[i].getSupportedDocFlavors() + " |||| "
+ pservices[i].hashCode());
}
PrintService pservice = pservices[1];
System.out.println("looked up service: " + pservice);
if (pservice != null) {
System.out.println("got service");
DocPrintJob pj = pservice.createPrintJob();
Doc doc = new SimpleDoc(this, flavor, aset);
try {
System.out.println("trying to print");
pj.print(doc, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}

OUTPUT & ERROR:
0: \\regs\HP LaserJet 4050 Series PCL |||| [Ljavax.print.DocFlavor;@c791b9 |||| 1273058671
1: ZTC Z4M-200dpi |||| [Ljavax.print.DocFlavor;@b15692 |||| 775228905
2: Symantec Fax Starter Edition |||| [Ljavax.print.DocFlavor;@aa9f99 |||| -1486058539
3: HP LaserJet 1200 |||| [Ljavax.print.DocFlavor;@d42d08 |||| 1922980968
looked up service: Win32 Printer : ZTC Z4M-200dpi
got service
trying to print
java.lang.ArrayIndexOutOfBoundsException
at sun.print.Win32PrintService.getDefaultAttributeValue(Win32PrintService.java:786)
at sun.print.Win32PrintJob.printableJob(Win32PrintJob.java:413)
at sun.print.Win32PrintJob.print(Win32PrintJob.java:342)
at com.mixonic.admin.print.ShipLabel.print(ShipLabel.java:146)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic