rspahitz
asked on
Printing a string
I'm looking for a "standard" solution to taking String contents from a textbox, asking the user to select a printer, then outputing the string to that printer.
I've tried the code below and it never finds any printers. Granted, I have none connected to my system, but two are located in my Windows printers list.
DocFlavor objInputFormat = DocFlavor.STRING.TEXT_PLAI N;
Doc objDoc = new SimpleDoc(strXML, objInputFormat, null);
PrintRequestAttributeSet objAttributeSet = new HashPrintRequestAttributeS et();
objAttributeSet.add(new Copies(1));
objAttributeSet.add(Sides. ONE_SIDED) ;
this.lblStatus.setText("Lo oking for valid printers...");
PrintService[] services = PrintServiceLookup.lookupP rintServic es(objInpu tFormat, objAttributeSet);
if (services.length > 0)
{
...
} else {
System.out.println("No printers found.");
}
I've tried the code below and it never finds any printers. Granted, I have none connected to my system, but two are located in my Windows printers list.
DocFlavor objInputFormat = DocFlavor.STRING.TEXT_PLAI
Doc objDoc = new SimpleDoc(strXML, objInputFormat, null);
PrintRequestAttributeSet objAttributeSet = new HashPrintRequestAttributeS
objAttributeSet.add(new Copies(1));
objAttributeSet.add(Sides.
this.lblStatus.setText("Lo
PrintService[] services = PrintServiceLookup.lookupP
if (services.length > 0)
{
...
} else {
System.out.println("No printers found.");
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
...continue.
Use PrinterJob (like doc says).
Bye, Giant.
Use PrinterJob (like doc says).
Bye, Giant.
ASKER
PCable, that seems to have worked, although the formatting has much to be desired. I guess I'll have to spend some tiem figuring the rest out.
Thx.
Giant, not sure what you mean about default printer. Cable's ref has PrinterJob.printDialog(); which brings up the dialog box, which was a step in the right direction.
Thx.
Giant, not sure what you mean about default printer. Cable's ref has PrinterJob.printDialog(); which brings up the dialog box, which was a step in the right direction.
Ok, good luck...
Giant.