 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Alpha Guest
|
Posted: Sat Mar 25, 2006 4:12 pm Post subject: Print error...please help |
|
|
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());
}
}
} |
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Tue Mar 28, 2006 6:12 pm Post subject: Re: Print error...please help |
|
|
"Alpha" <alphaforcex (AT) gmail (DOT) com> wrote in message
news:1143300335.253120.175170 (AT) i39g2000cwa (DOT) googlegroups.com...
| Quote: | 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
|
[...]
| Quote: | 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 |
|
| Back to top |
|
 |
Alpha Guest
|
Posted: Thu Mar 30, 2006 4:12 am Post subject: Re: Print error...please help |
|
|
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. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|