I want to print .ps file from java

Hello
i want to print .ps file using javax.print api and this give following error
sun.print.PrintJobFlavorException: invalid flavor
and my code is as below
public PrintPS() {
          /* 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
          //DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
          DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
          PrintRequestAttributeSet aset =
               new HashPrintRequestAttributeSet();
          aset.add(MediaSizeName.ISO_A4);
          aset.add(new Copies(2));
          aset.add(Sides.TWO_SIDED_LONG_EDGE);
          aset.add(Finishings.STAPLE);
          System.out.println("HI");
          /* locate a print service that can handle it */
          PrintService pservices =
               PrintServiceLookup.lookupDefaultPrintService();
          System.out.println("Hello "+pservices);
          DocFlavor[] flavors = pservices.getSupportedDocFlavors();
          for (int i = 0; i < flavors.length; i++) {
          System.out.println(flavors.getRepresentationClassName());
     /*     if (pservices.length > 0) {*/
               System.out.println("selected printer " + pservices.getName());
               /* create a print job for the chosen service */
               DocPrintJob pj = pservices.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("hexagon.ps");
                    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);
plz help me

1. Turn the router, iPad and printer off.
2. Turn on the router and then wait 30 seconds to let it complete its start-up process.
3. Turn on printer and then wait 30 seconds to let it complete its start-up process.
4. Turn on your iPad and test print.

Similar Messages

  • I wants to call .Exe file from Java Programme

    I wants to call .Exe file from Java programme. Please give answer with example. This very urgent. Help me

    hi
    u can use Runtime.exec() method in java.lang package
    to execute exe files
    regards
    pnp

  • Printing RTF files from Java

    Hello,
    I need to print RTF files from a java program. I am reading RTF files in my program and after modification need to send them to a network printer for printing.
    Please let me know if there are any tutorials/books available on this.
    Thank you very much,
    Regards,
    Vaishali

    check these urls. may help u some extent.
    http://java.sun.com/docs/books/tutorial/2d/printing/index.html
    http://www.javaworld.com/javaworld/jw-03-2001/jw-0302-print.html
    http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html

  • How to print PDF file from java application?

    Hi,
    I have a java application that needs to print an PDF files. Could any one provide me links to tutorial/sample codes for doing this?

    http://onesearch.sun.com/search/onesearch/index.jsp?qt=print+pdf+files&subCat=&site=dev&qp=&chooseCat=javaall&col=developer-forums

  • Viewing and printing a PDF file from Java Swing Application

    Hello,
    I need to view and print PDF files from Java Swing Application.How do I do that?I appreciate your help.
    Thank you
    Sumana Somareddy

    If you have a link to the URL pointing to the PDF file, you can allow the browser to open it. Then use the print function of the browser to print the PDF document.
    Regards,
    Tak.

  • How to Call .XDO file From Java Program

    Hi,
    I have developed a report in using BI Publisher version 10.1.3.
    I created the report and it only created XDO files. If I want to call XDO file from Java program how I can do that.
    What are the APIs available to do that.
    Thanks
    -Ashutosh

    Hi,
    the JavaAPI didn't work with the xdo-Files. But you can create a proxy stub for the Web Service API of BI Publisher which uses the xdo's in the repository.
    regards
    Rainer

  • How can i call forpro prg file from java

    Hai friends,
    I have a doubt,clear it.
    how can i call forpro prg file from java file
    by,
    N.Vijay

    Thanks to your reply,
    I have some print statements in my foxpro program file.
    Then i like to invoke that foxpro file from my java file
    This want i want..,
    by,
    N.Vijay

  • Generation of xml file from java code

    hi,
    I want to manipulate data in a xml file with java code.I have read data from xml file and also changed it. But i am unable to covert it again in xml file from java code. Can you please tell me how i can do this?

    Let me know which parser are you using currently for reading xml files so that i assist you. For now, you can refer to STAX Parser API under this link
    http://java.sun.com/webservices/docs/1.6/tutorial/doc/SJSXP3.html

  • How can i print my files from mi iphone 5 throught the airport express?

    How can i print my files from mi iphone 5 throught the airport express?? i have the last iOS version installed and also the last firmware version of the printer. the printer is already connected to the USB airport express and when i look for printers in airprinter there is no printer found. i have an HP LASERJET P1606dn(i think that is supported by the airprinter).

    In order to function with AirPrint, a printer must connect to the network wirelessly.
    Even if you have an AirPrint compatible printer, iOS devices will not be able to print to the printer when it is connected via USB.
    So, you have two options:
    1) Reconfigure the printer to connect to the network using wireless only and the iOS devices should be able to print that way....assuming that you have up to date drivers for the printer installed.
    2) Leave the printer connected via USB and then use a third party App like Printopia installed on your Mac as a "workaround" to (hopefully) allow the iOS to device to be able to print.  If you want to give this a try, there is a free trial for Printopia, so you will know if it will work before you buy. You must have a Mac running on the network in order for Printopia to function correctly.
    Printopia - AirPrint to Any Printer - Print from iPad - Print from iPhone ...

  • Print Jpeg files from SAP

    Hi,
    We have JPEG files (pictures) stored in Custom Z table (Cluster table). We would like to know how to print these files from SAP on to a certain printer.
    We know that it is not possible to convert JPEG to BMP within SAP and print using SAPScript OR SmartForms.
    We want to find out if there is any print command to print these files to SAP printer  ?
    Any help is appreciated.
    Niranjan

    Hi Gregory,
    I had checked this tcode earlier. However, I don't see any 'Print' jpeg or any other file functionality here. What SAP might be doing here is, allow upload of any document like excel, word or pic files (jpeg, gihf, bmp) and so on and just display.
    I am interested in printing functionality without usng SAP Script OR Smartforms, because, when we get into it, we have to talk only TIF or BMP as JPGs are not supported.
    Niranjan

  • How to edit the existing data in the XML file from java programming.

    Hi all
    i am able to create XML file with the sample data as below from java programming.
    i need sample code on how to edit the existing data in the XML file?
    for example
    <?xml version="1.0"?>
       <mydata>
               <data1>
                         <key1>467</key1>
                        <name1>Paul</name1>
                        <id1>123</id1>
              </data1>
              <data2>
                         <key2>467</key2>
                        <name2>Paul</name2>
                        <id2>123</id2>
              </data2>
        </mydata>
    i am able to insert the data in the XML.
    now i need sample code on how to modify the data in the above XML file from the java programming for only key2,name2,id2 tags only. the remaining tags data in the XML file i want to keep same data except for key2,name2,id2 which are i want to modify from java code
    Regards
    Sunil
    [points will be always rewardable]

    hi
    u need a parser or validate the xml file for to read the xml file from java coding u need for this
    xml4j.jar u can download this file  from here
    http://www.alphaworks.ibm.com/tech/xml4j
    or we can use the SAX(simple API for XML)
    some sample applications for this
    http://www.java-tips.org/java-se-tips/javax.xml.parsers/how-to-read-xml-file-in-java.html
    http://www.developertutorials.com/tutorials/java/read-xml-file-in-java-050611/page1.html
    http://www.xml-training-guide.com/e-xml44.html
    let me know u need any other info
    bvr

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • Creating XML file from Java Bean

    Hi
    Are there any standard methods in Java 1.5 to create XML file from java bean,
    i can use JAXB or castor to do so,
    But i would like to know if there is any thing in java core classes,
    I have seen XMLEncoder, but this is not what i want.
    Any ideas
    Ashish

    Marshall JavaBean to an XML document with JAXB or XMLBeans.

  • How to modify an existing xml file from java code.

    Hi
    I have worked on creating a new xml file from java code using xmlbeans.But if i try to modify an already existing file using java code I am unable to get errorfree xmlfile.
    For example if xml file(studlist.xml) is as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    Now suppose i have set name to victor using student.setName,
    and set age to 20 using setAge from javacode,
    the new xml file is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <StudentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\kchaitanya\xmlprac1\abc\Studlist.xsd">
         <Student>
              <Name>ram</Name>
              <Age>27</Age>
         </Student>
    <Student>
              <Name>sham</Name>
              <Age>26</Age>
         </Student>
    </StudentList>
    <Student>
              <Name>victor</Name>
              <Age>20</Age>
         </Student>
    As observed this is not a valid xml file.But how can i modify without any errors?

    I know it's an old post, but I found this while doing a google search for something else, and don't like to leave it un-aswered
    Just in case anyone has a similar problem... In this case the new elements have been appended outside of the root element
    What you need to do is first get the root element and then append the new children to that, there are several ways of getting the root element, which depend on what you want to do with the elements you get back here's a simple (incomplete) way.
    // gets the root element of the specified file (code not shown)
    Element rootElement= new SAXReader().read(file).getRootElement();Then just append the new elements as below (this is non-generic code and would need to be modified for your situation)
    // write a new student element
    Element student = document.createElement("Student");  // creates the new student
    rootElement.appendChild(student); // ***appends it to the root element***
    Element name = document.createElement("Name"); // creates the name element
    name.appendChild(document.createTextNode("Fred")); // adds the name text to the name element
    student.appendChild(name); // appends the name to the student
    Element age= document.createElement("Age"); // creates the age element
    age.appendChild(document.createTextNode("26")); // adds the age text to the age element
    student.appendChild(age); // appends the name to the studentThen flush ya buffers or whatever and write the file
    Edited by: Dream-Scourge on Apr 23, 2008 11:10 AM

  • Can't print pdf files from my imac

    can't print pdf files from my imac.

    macs don't come with acrobat reader by default
    when one get a mac and open a pdf file the build in program called preview opens it
    most of us stick with preview because acrobat reader is a rather dangerous program to install
    http://www.cvedetails.com/vulnerability-list/vendor_id-53/product_id-497/cvsssco remin-6/cvssscoremax-6.99/Adobe-Acrobat-Reader.html
    more
    https://www.google.com/search?sourceid=opera-portal&q=acrobat+reader+exploits&cl ient=opera-portal&channel=portal#hl=en&client=opera-portal&hs=lqn&channel=portal &sclient=psy-ab&q=list+of+acrobat+reader+exploits&oq=list+of+acrobat+reader+expl oits&gs_l=serp.3...8463.9471.0.9773.8.7.0.0.0.1.162.508.6j1.7.0.les%3B..0.0...1c .1.5.psy-ab.4Tc73RiiXXA&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.43148975,d .bGE&fp=cab576d3b9062d9c&biw=1825&bih=748
    after adobe flash and oracle Java the adobe acrobat reader is the most open door for hackers into ones system
    if you type preview in spotlight(the icon which looks like a spyglass) or in the launch's seach you can get to the preview app

Maybe you are looking for