Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2006

Tip: Looking for answers? Try searching our database.

Print error...please help

Thread view: 
Alpha - 25 Mar 2006 16:25 GMT
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 - 28 Mar 2006 18:37 GMT
> This is my simple print method. For some reason, I always got error
> when I try to print
[quoted text clipped - 3 lines]
> Selected printer:LB1022
> Print Error:java.io.IOException: No such file or directory

[...]
>            DocPrintJob job =
> services[selectedPrinter].createPrintJob();
[quoted text clipped - 3 lines]
>                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 - 30 Mar 2006 04:23 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.