Home > Archive > Java Help > March 2006 > Print error...please help
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Print error...please help
|
|
| Alpha 2006-03-25, 10:02 pm |
| This is my simple print method. For some reason, I always got error
when I try to print
job.print(myDoc, aset);
Output:
Selected printer:LB1022
Print Error:java.io.IOException: No such file or directory
I tried printing it to the printer from the unix prompt with no
problem.
lp -d LB1022 some_file
and this works.
Any ideas??
public void print(String printer, String label) throws Exception {
InputStream textstream = null;
textstream = new ByteArrayInputStream(label.getBytes());
// Set the document type
DocFlavor myFormat =
DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
// Create a Doc
Doc myDoc = new SimpleDoc(textstream, myFormat, null);
// Build a set of attributes
PrintRequestAttributeSet aset = new
HashPrintRequestAttributeSet();
// discover the printers that can print the format according
to the
// instructions in the attribute set
PrintService[] services =
PrintServiceLookup.lookupPrintServices(myFormat, aset);
int selectedPrinter=0;
// Check to see if the specify printer is a valid printer
for (int row=0; row<services.length; row++) {
if (services[row].getName().equals(printer)) {
selectedPrinter=row;
}
}
if (services[selectedPrinter] != null) {
System.out.println("Selected printer:" +
services[selectedPrinter].getName());
DocPrintJob job =
services[selectedPrinter].createPrintJob();
try {
job.print(myDoc, aset);
} catch (PrintException pe) {
System.out.println("Print Error:" + pe.getMessage());
}
}
}
| |
| Oliver Wong 2006-03-28, 7:04 pm |
|
"Alpha" <alphaforcex@gmail.com> wrote in message
news:1143300335.253120.175170@i39g2000cwa.googlegroups.com...
> This is my simple print method. For some reason, I always got error
> when I try to print
> job.print(myDoc, aset);
>
> Output:
> Selected printer:LB1022
> Print Error:java.io.IOException: No such file or directory
[...]
> DocPrintJob job =
> services[selectedPrinter].createPrintJob();
> try {
> job.print(myDoc, aset);
> } catch (PrintException pe) {
> System.out.println("Print Error:" + pe.getMessage());
> }
Try replacing the above with the following code, printing the output, and
giving it to us.
<code>
DocPrintJob job = services[selectedPrinter].createPrintJob();
try {
job.print(myDoc, aset);
} catch (PrintException pe) {
System.out.println(pe.getMessage());
System.out.println(pe.getClass().getName());
if (pe instanceof FlavorException) {
System.out.println("Flavor Exception");
FlavorException fe = (FlavorException)pe;
//I'm guessing this is not the problem.
System.out.pritnln("You guessed wrong.");
} else if (pe instanceof AttributeException) {
System.out.println("Attribute Exception");
AttributeException ae = (AttributeException)pe;
if (ae.getUnsupportedAttributes() != null) {
for (int i = 0; i < ae.getUnsupportedAttributes().size; i++) {
System.out.println("Unsupported attribute: " +
ae.getUnsupportedAttributes()[i]);
}
}
if (ae.getUnsupportedValues() != null) {
for (int i = 0; i < ae.getUnsupportedValues().size; i++) {
System.out.println("Unsupported values: " +
ae.getUnsupportedValues()[i].getName());
}
}
}
}
</code>
- Oliver
| |
| Alpha 2006-03-29, 10:02 pm |
| Thanks, I'll try this when I get back to work tomorrow and post my
results. I'm suspecting that this may have something to do with the way
I setup the printer in the unix environment.
|
|
|
|
|