Can anyone tell me why this doesnt' work please

Be gentle :o)
I am trying out this printing in version 1.4 I am wanting to print out the contents of a text file
Below is the code but it does nothing
It compiles but doesn't function??
HELP
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
public class PrintFile {
     public static void main(String args[]) {
          PrintFile pf = new PrintFile();
     public PrintFile() {
          /* Construct the print request specification.
          * The print data is Postscript which will be
          * supplied as a stream. The media size
          * required is A4, and 1 copy are to be printed
          DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST;
          PrintRequestAttributeSet aset =
               new HashPrintRequestAttributeSet();
          aset.add(MediaSizeName.ISO_A4);
          aset.add(new Copies(1));
          aset.add(Sides.TWO_SIDED_LONG_EDGE);
          aset.add(Finishings.STAPLE);
          /* locate a print service that can handle it */
          PrintService[] pservices =
               PrintServiceLookup.lookupPrintServices(flavor, aset);
          if (pservices.length > 0) {
               System.out.println("selected printer " + pservices[0].getName());
               /* create a print job for the chosen service */
          DocPrintJob pj = pservices[0].createPrintJob();
               try {
                    * Create a Doc object to hold the print data.
                    * Since the data is postscript located in a disk file,
                    * an input stream needs to be obtained
                    * BasicDoc is a useful implementation that will if requested
                    * close the stream when printing is completed.
                    FileInputStream fis = new FileInputStream("EventFile.txt");
                    Doc doc = new SimpleDoc(fis, flavor, null);
                    /* print the doc as specified */
                    pj.print(doc, aset);
                    * Do not explicitly call System.exit() when print returns.
                    * Printing can be asynchronous so may be executing in a
                    * separate thread.
                    * If you want to explicitly exit the VM, use a print job
                    * listener to be notified when it is safe to do so.
               } catch (IOException ie) {
                    System.err.println(ie);
               } catch (PrintException e) {
                    System.err.println(e);
}

I too find the same problem not locating all the print services, then i use defualt print service and it works, another error i was getting that of invalid flavor so i then get all the doc flavor supported by my printer and use AUTOSENSE. Following is the code that u can test:
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
public class PrintText1 {
     public static void main(String[] args) {
          System.out.println("Print Text");
          PrintText1 ps = new PrintText1();
     public PrintText1() {
          /* Construct the print request specification.
          * The print data is Postscript which will be
          * supplied as a stream. The media size
          * required is A4, and 2 copies are to be printed
          System.out.println(0);
          DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
          PrintRequestAttributeSet aset =
               new HashPrintRequestAttributeSet();
          aset.add(MediaSizeName.ISO_A4);
          aset.add(new Copies(1));
          aset.add(Sides.ONE_SIDED);
          //aset.add(Finishings.STAPLE);
          /* locate a print service that can handle it */
          System.out.println(1);
          PrintService defpservices = PrintServiceLookup.lookupDefaultPrintService();
          System.out.println("Default Printer " + defpservices.getName());
          /* create a print job for the chosen service */
          DocPrintJob pj = defpservices.createPrintJob();
          System.out.println(2);
          try {
               * Create a Doc object to hold the print data.
               * Since the data is postscript located in a disk file,
               * an input stream needs to be obtained
               * BasicDoc is a useful implementation that will if requested
               * close the stream when printing is completed.
               FileInputStream fis = new FileInputStream("file.txt");
                    Doc doc = new SimpleDoc(fis, flavor, null);
                    System.out.println(3);
                    /* print the doc as specified */
                    pj.print(doc, aset);
                    * Do not explicitly call System.exit() when print returns.
                    * Printing can be asynchronous so may be executing in a
                    * separate thread.
                    * If you want to explicitly exit the VM, use a print job
                    * listener to be notified when it is safe to do so.
          } catch (IOException ie) {
               System.err.println("IOException " + ie);
          } catch (PrintException e) {
               System.err.println("PrinterException " + e);
Try this code it will work for you to print the text file.
Now my problem is i am trying to print the html file and its printing the html file including all the html tags, can anybody help how can i be able to print only that area that viewable to user in the internet explorer and not all the html tags:
Following is my code which i had written using servlet:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.util.Properties;
import java.net.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import javax.print.event.*;
public class printServlet extends HttpServlet
     public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException
          // Set the mime type
          response.setContentType("text/html");
          // Create a PrintWriter Object
          PrintWriter out = response.getWriter();
          /* Construct the print request specification.
          * The print data is HTMl which will be
          * supplied as a stream. The media size
          * required is A4, and 1 copies are to be printed
          System.out.println(0);
          //DocFlavor htmlFlavor = DocFlavor.URL.TEXT_HTML_US_ASCII;
          DocFlavor htmlFlavor = new DocFlavor("application/octet-stream", "java.net.URL");
          PrintRequestAttributeSet aset =
               new HashPrintRequestAttributeSet();
          aset.add(MediaSizeName.ISO_A4);
          aset.add(new Copies(1));
          aset.add(Sides.ONE_SIDED);
          /* locate a print service that can handle it */
          System.out.println(1);
          //PrintService[] pservices =
               //PrintServiceLookup.lookupPrintServices(htmlFlavor, aset);
          PrintService pservices = PrintServiceLookup.lookupDefaultPrintService();
               //System.out.println("Printer Length " + pservices.length);
               //PrintService service = pservices[0];
          System.out.println("selected printer " + pservices.getName());
          DocFlavor[] sdf = pservices.getSupportedDocFlavors();
          System.out.println("Supported DocFlavors are: ");
          for( int r = 0; r < sdf.length; r++ )
               System.out.println(sdf[r].toString());
          /* create a print job for the chosen service */
          String urlString = "http://localhost:8080/printengine/jsp/hello.html";
          URL url = new URL(urlString);
          DocPrintJob pj = pservices.createPrintJob();
          Doc doc = new SimpleDoc(url, htmlFlavor, null);
          out.println("<html><body>" + doc + "</body></html>");
          System.out.println(3);
          /* print the doc as specified */
          try
               pj.print(doc, aset);
               System.out.println(4);
               * Do not explicitly call System.exit() when print returns.
               * Printing can be asynchronous so may be executing in a
               * separate thread.
               * If you want to explicitly exit the VM, use a print job
               * listener to be notified when it is safe to do so.
               out.println("<html><body>Printing Successful</body></html>");
          catch (PrintException e)
               System.err.println("PrinterException " + e);
Please help me out

Similar Messages

  • When I switch libraries I lose the majority of the material in my main library and can only restore it by repairing the database. Can anyone tell me why this is happening and how I can resolve the problem? Thanks

    When I switch libraries I "lose" the majority of the material in my main library (or at least I can't see it) and can only restore it by repairing the database. Can anyone tell me why this is happening and how I can resolve the problem? Thanks

    I seem to have found a way around it. Rather than switching libraries by going into files/switch libraries I used Aperture Preferences to change them. I've done it a couple of times and it appears to work OK.
    That is an interesting finding. It suggests, that your "Preferences" file "com.apple.Aperture.plist" may have been corrupted and you fixed it this way. Can you now switch between libraries the usual way? If not, I'd try to remove the "preferences" file from the user library to the Desktop and relaunch Aperture.
    The Aperture 3: Troubleshooting Basics:http://support.apple.com/kb/HT3805
    describe how to remove the user preferences.

  • I want to reset my privacy questions for my apple i.d. But when i request to do so it sends it to a email address that isnt on my file can anyone tell me why its not working?

    I want to reset my privacy questions for my apple i.d. But when i request to do so it sends it to a email address that isnt on my file can anyone tell me why its not working?

    1)  Apple ID: All about Apple ID security questions
    Torrifromny wrote:
    I want to reset my privacy questions for my apple i.d. But when i request to do so it sends it to a email address that isnt on my file ?
    2)  See Here.  Apple ID: Contacting Apple for help with Apple ID account security
    Ask to speak with the Account Security Team...
    3)  Or Email Here  >  Apple  Support  iTunes Store  Contact

  • HT1766 I can't get my iPod to "backup" to iCloud. It started and told me the estimated time remaining. When I came back, it said it couldn't be completed because the verification request timed out. Can anyone tell me why this keeps happening?

    I've tried several times to get it to Backup to iCloud. But every time I do, it will start and say it is "backing up". Then after a few minutes, it tells me that the backup could not be completed because the verification timed out. Can anyone tell me how to fix this?

    I suggest that you Contact Customer Care - click on the Still need help? button to chat with an agent.

  • I updated to Firefox 4 and there's no orange Firefox button and the Menu Bar is still there (File, Edit, View, etc.). Can anyone tell me why this is happening?

    As the question states, I tried updating from Firefox 3 to Firefox 4 two different ways and though I see a difference, it's definitely not all of Firefox 4. I updated with the auto update installer and downloaded the exe and installed and it's still not right. I don't have the new Firefox style or the Infamous Orange Firefox button. My Menu Bar (File, Edit, View, Etc...) is still there as well. The only thing that has really changed is the tabs going above the URL bar. Can anyone tell me how to fix this?

    To get the new style UI you need to hide the menu bar. To do that in the View menu select Toolbars, then click on the "Menu Bar" entry.
    If you need access to the menus you can press either Alt or F10 to temporarily display them.

  • Can anyone tell me why this error only occur in Tomcat-4.0.2 ??

    When I try to execute my jsp page, Tomcat printed out this error.
    This error has never occurred in Tomcat-3.2.1 and Tomcat-3.3a.
    java.io.IOException: Stream closed
         at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:242)
         at org.apache.jasper.runtime.JspWriterImpl.clearBuffer(JspWriterImpl.java:190)
         at org.apache.jsp.admin_0005flogin$jsp._jspService(admin_0005flogin$jsp.java:988)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
         at java.lang.Thread.run(Thread.java:536)
    Another thing is, I'm trying to display chinese characters using jsp page. When I use Tomcat-3.2.1, i can view the chinese characters correctly, but when I converted to Tomcat-3.3a (due to the newer version of JDBC API available in Tomcat-3.3a), it don't seems to recognize the html META Header that I use to encode the jsp page.
    Is there anyway if making Tomcat-3.3a read the header or what ???
    Can anyone enlighten me on this ??
    I really need to get the solution or the reason ASAP !!
    Thank you in advance.

    Hi,
    I dont know whether you are still getting the error. This error seem to be result of closing the output stream accidently or manually for some reason. so look out for 'out.close' or other 'out' operations which deals either with flushing or closing the stream. By removing the statement I solved this problem.
    if u have any questions: contact me on [email protected]
    Thanks.

  • Hi, I have downloaded a tv episode from itunes and would like to copy it to a usb flashdrive to watch on my tv which has a usb port, can anyone tell me if this is possible please?  I can see the tv episode in my Library but i can't drag to usb drive

    Hi
    I have downloaded a tv episode from itunes, I would like to watch it on my tv, not the computer.
    My tv has a usb port, what I would like to do is copy tv episode to usb flash drive and then play on my tv.
    I have tried dragging the episode from the library to the usb drive, I thought I had been successful but when I looked it was just text.
    Can anyone advise if it is possible please ?

    It won't work, they are linked to your account and can only be played via iTunes on a computer, an iOS device or Apple TV. You might be able to get a cable to link your Mac to your TV so that you can play/mirror it through your TV e.g. if it's a Macbook with an HDMI socket and your TV also has an HDMI socket then you could try an HDMI to HDMI cable (Apple do them, and electrical stores should also have them) - I've used one to play iTunes TV programmes on my TV (though I don't think that I got sound through my TV, only my Mac).
    Message was edited by: King_Penguin

  • I have a TON of bookmarks that I want to back up, but when I open the window to organize them, back them up, etc., none of them are there! Can anyone tell me why this is happening and how to fix it?

    On the dropdown menu where my bookmarks are, I select "show all bookmarks", which opens up a window called "Library". I should have hundreds of bookmarks, but none of them are showing in this window.

    This can be a problem with the file places.sqlite that stores the bookmarks and the history.
    * http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox

  • Can anyone tell me why this project is sticking in the timeline?

    Hi guys.
    I have been using FCP for a while now with great success.
    Generally I record on my handycam which is a mini DVD format. then I process the clips though mpg streamclip to DV pal and they become ".mov" files. (I do this to demux the clips audio from the video)
    Then I have no problems working in the time line.
    But recently I introduced a new camera to the mix.
    It is a head cam, A 1.3 Mpixel CMOS Senor, video and audio, 640x480 at 30 frames per second. It records onto a micro SD card in avi format.
    Now when I drop these files into the time line I experience a lot of "Choking" and "Pausing" from the computer.
    It seems that the hard drive cannot handle the footage. Even when I place the playhead over the normal ".mov" files it struggles.
    And even when I make a quicktime movie from the sequence I have the same previewing trouble in quicktime or any other media player for that matter.
    My Tech specs are as follows.
    A 13 month old Mac Book Pro with 4GB ram, External USB hard drive for the clips. (but it's the same when clips are stored on the desktop).
    So do I need to convert these avi files through mpeg streamclip to ".mov" files first as I do with my other files, in order to be able to work with them?

    As this is essentially the same subject as your topic from yesterday, please try to keep the discussion all in the same thread: http://discussions.apple.com/thread.jspa?threadID=2050214&tstart=0
    You also have new responses there.

  • Can anyone tells me why this fails?

    Maybe I'm missing something?
    var chapterStyles = [
          doc.paragraphStyles.item("ChapterTitle (Chapter)"),
          doc.paragraphStyles.item("FrontBackTitle (Chapter)")
    alert(chapterStyles[0].name);
    If you change the alert to  ChapterStyles[0]  it works... seems like this should be pretty simple.

    Josh,
    Your variable contains invalid references.
    If you try this:
    alert(chapterStyles[0].isValid);
    it will return false because
    doc.paragraphStyles.item("ChapterTitle (Chapter)")
    is not valid, but it didn't returns error if item is not found.
    Hope that helps.
    Marijan (tomaxxi)
    http://tomaxxi.com

  • Can anyone tell me why a picture would change color when I try to download/upload it?  It is the exact same picture- chosen the same way and when it goes to any other program it changes the color (I've tried canvas on demand and mpixpro.  I've also tried

    Can anyone tell me why this picture changes color when I try to download/upload it?  It is the exact same picture I have taken from the same location.  The image on the left is via preview and the image on the right is what is shows like when I try to download it.  I have emailed it to myself and it shows fine on the computer and in CS4, but when I look at the download via my phone or on another computer it shows the wonky color on the right.  I have checked the color space shows RGB/8 bit.  Any ideas why or how to fix it?  It isn't with any one specific session.... and I've tried it on both my desktop and my laptop- saved image to an external hard drive and to drop box.  I've tried sending the image to canvas on demand, my email, mpxipro, POST editing- all the same result.  Please HELP!!  What am I doing wrong?

    Most of the time you see something like that. The image in question has a color profile other then sRGB. Some image viewers/displayers are color managed and others are not.  So the image do not look the same in all of the applications you use. So colors seem to change.
    Try converting it to sRGB color and see if then looks the same all around. Also I think PC and Mac displays are set to different gamma something like 1.8 and 2.2
    Though I'm colorblind I even see color variations.

  • When i open safari it is very slow but once it has opened i can switch web sites very quick, can anyone tell me why.

    I have a problem when i open Safari.it takes a few minutes to open, the home page opens but if i try to open ( say Amazon) it just sits there for more minutes before opening ,but once it has opened i can switch from web site to web site very quick.can anyone tell me why this and is there anything i can do to 

    Try changing the "Top Sites shows:" to the smallest number possible.  Safari is loading these sites when its starts so it can give you an image of what the site looks like when you start blank new window.  A smaller number of sites will make that quicker, assuming the top sites do not have a very slow site in the mix.

  • Several times I've downloaded albums from iTunes to find that some of the tracks did not get fully downloaded so that the track with skip to the next one. Can someone tell me why this is happening and how I can fix it?

    Several times I've downloaded an album from iTunes to find that not all of the tracks were fully downloaded so that some of the tracks will skip to the next one (instead of finishing the song). Can anyone tell me why this happens and how I can fix it?

    If your country's iTunes Store allows you to redownload purchased tracks, I'd delete your current copies of the tracks and try redownloading fresh copies.
    Otherwise, I'd report the problem to the iTunes Store.
    Log in to the Store. Click on "Account" in your Quick Links. When you're in your Account information screen, go down to Purchase History and click "See all".
    Find the items that are not playing properly. If you can't see "Report a Problem" next to the items, click the "Report a problem" button. Now click the "Report a Problem" links next to the items.
    (Not entirely sure what happens after you click that link, but fingers crossed it should be relatively straightforward.)

  • I have a brand new macbook pro 15" with latest Lion.Can anyone tell me why, when I open word or preview etc that multiple files open?For eg if I open a word doc, the last 1-3 docs that I have worked on all open. why?

    I have a brand new macbook pro 15" with latest Lion. Can anyone tell me why, when I open word or preview etc that multiple files open?For eg if I open a word doc, the last 1-3 docs that I have worked previously on all open. Can anyone tell me why?

    You have a choice as to whether or not applications in Lion like Word or Preview (or even Safari) save and re-open previous documents or windows... just hold down the option key while quitting a program and when you re-open it you won't get the previous documents or windows when you re-open the application. You can see this by selecting the open program in the menu bar and when holding down the option key the quit function will change to quit and discard open windows. This feature in Lion is referred to as "Resume" and is great if you want to restart an app and return to what you're doing (for example in Safari re-opening existing windows and tabs from your previous session). You still have the option to close individual windows within an app before quitting and they will not re-open when the app is launched again.
    This Resume function is not related to saving your work (a word or text document for example). This is handled by Lion's "Auto-Save" and "Versions" functions. See http://www.apple.com/ca/macosx/whats-new/auto-save.html
    Hopefully this is the complete answer you're looking for.

  • Can anyone tell me why my collusion .27 add-on stopped working when I updated to firefox 20 (and now 21?).

    Can anyone tell me why my collusion .27 add-on stopped working when I updated to firefox 20 (and now 21?). I've tried removing and reinstalling to no avail. I even deleted my profile files and had firefox repopulate those automatically to no avail. And it's not the only add-on to have stopped working.

    see here
    *https://support.mozilla.org/en-US/kb/re-enable-add-ons-disabled-when-updating
    Addons are enabled or disabled?

Maybe you are looking for

  • How to get the display value of selected item in list box?

    I have a page with an HtmlSelectOneListbox that is filled with an ArrayList of SelectItem objects. The SelectItem objects contain a Key and Value. The Value is displayed in the ListBox. The value parameter of the listbox is bound to a bean property w

  • Font source in Labview on Kubuntu

    Hello everybody, can anybody tell me from where Labview reads the font list entries in the font dialog? I want to run my application on different linux systems (Lv80 on Kubuntu and Suse Enterprise Server 10.0) and face the same problems with the font

  • Will Airplay work without AppleTV?

    Hello - can you please let me know that now i have downloaded the latest ipad software 4.2 and when I play a movie, the airplay icon does not a appear, this may be a silly question - but do I need to have an Apple TV box first for the feature / logo

  • CJC channel does not show up in MAX

    Greetings,     I have an SCXI 1124 that I am reading in 32 TC's with.  When I try to configure it for CJC internal under MAX for physical channel it does not show up as described in "DAQmx Acquire CJC Temperature".  In that document the CJC physical

  • I get repeated crashes of Adobe Flash using the latest Firefox version.  Anyone have any suggestions

    Since I upgraded to win 8 yesterday, firefox has not run the same at all.  it is slow, the browser blinks on any page that uses flash.  the plugin crashes or simply just shuts when i try to play a video on youtube or vimeo.  I have troubleshooted all