This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes Trouble Printing with java 1.4! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Trouble Printing with java 1.4!" Watch "Trouble Printing with java 1.4!" New topic
Author

Trouble Printing with java 1.4!

Andrew Keidel
Greenhorn

Joined: Dec 06, 2001
Posts: 27
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble Printing with java 1.4!
 
Similar Threads
How to get List of Client Printers
Using printer to print string object
Printing to Wireless printer.
javax.print in ejb
Printing Error while printing txt file