Does java print service support word docs or text files

Can anyone tell me that java print service api allows to print word doc files or RTF files etc.

no it doesn't.
To print a Word Doc you need to be able to read it, and display it.
Anything that can be displayed in, say a JPanel, can be printed, cos it's just a matter of displaying the
image to a virtual component ( a print canvas ). Which then gets printed.
So, because Java doesn't immediately support Ms Docs, neither does the print service.
regards,
Owen

Similar Messages

  • Printing a microsoft word doc using Java Print API

    Hi,
    I have to print a microsoft word doc.I am using Java Print API, but the code is printing only Hashcodes instead of the actual document.
    Here is the code. Please let me know whats wrong in it.
    CODE:::
    public String print() throws Exception {
    String realPath = getRealPath("/images/formLibrary/csaAddressContactRequestForm100.doc");
    PrintRequestAttributeSet pras1 = new HashPrintRequestAttributeSet();
    DocFlavor flavor1 = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
    DocPrintJob job = defaultService.createPrintJob();
    FileInputStream fis1 = new FileInputStream(realPath);
    DocAttributeSet das = new HashDocAttributeSet();
    Doc doc1 = new SimpleDoc(fis1, flavor1, das);
    job.print(doc1, pras1);
    Thread.sleep(10000);
    System.exit(0);
    return "";
    }

    By using an appropriate library. JText, whatever.
    Google, man.I think Rene meant iText!Whatever. :) Never used it, I just remembered there was something named like that. Thanks.

  • Java Print Service API in Java Stored Procedure (Linux)

    Hi
    We are running an Oracle 10g database on Linux and I am in the proces of developing a java stored procedure which should utilize the Java Print Service API.
    I have made a simple stored procedure to list all available printers and the DocFlavors they support (se the code below).
    My problem is that no printers are listed. I have made a standalone java app. with the same code and executed it directly on the OS level of the Linux box through the Sun JDK 1.4.2 and here I get two printers.
    Is there any specific configuration I need to do to make it work?
    I am wondering if I need to grant specific authorisations through dbms_java for it to work...?
    Any help is greatlyh appreciated.
    ************************************** CODE BEGIN *************************************
    import javax.print.DocFlavor;
    import javax.print.PrintService;
    import javax.print.PrintServiceLookup;
    import javax.print.attribute.HashPrintRequestAttributeSet;
    import javax.print.attribute.PrintRequestAttributeSet;
    public class TestPrintService {
    public TestPrintService() {
    public static void listPrinters() {
    // Get all available printers and their supported DocFlavors
    PrintService[] pservices =
    PrintServiceLookup.lookupPrintServices(null, null);
    System.out.println("Printer services: " + pservices.length);
    for (int i = 0; i < pservices.length; i++) {
    PrintService pservice = pservices;
    System.err.println("Printer: " + pservice);
    DocFlavor[] docFlavors = pservice.getSupportedDocFlavors();
    for (int j = 0; j < docFlavors.length; j++) {
    DocFlavor docFlavor = docFlavors[j];
    System.err.println("DocFlavor " + docFlavor.toString());
    System.err.println();
    ************************************** CODE END *************************************
    Cheers,
    Jacob Vennervald

    Found this on Oracle support:
    Cannot List Available Printers From The Database Using A Java Stored Procedure [ID 372694.1]
    Applies to:
    Oracle Server - Enterprise Edition - Version: 10.1.0.4.0
    This problem can occur on any platform.
    Symptoms
    Able to list available printers on a machine when running Java code outside the Database.
    When running the same Java code inside the Database as a Java Stored Procedure, no printers are found.
    Cause
    Due to security restrictions, this is expected results.
    The Java Docs state:
    "Services which are registered by registerService(PrintService) will not be included in lookup
    results if a security manager is installed and its CheckPrintJobAccess() method denies access."
    Also from the documentation it states:
    "A PrintServiceLookup implementor is recommended to check for the SecurityManager.checkPrintJobAccess() to deny access to untrusted code. Following this recommended policy means that untrusted code may not be able to locate any print services. Downloaded applets are the most common example of untrusted code."
    Using the checkPrintJobAccess(); call, it does produce a Security Exception when run inside the Database but not when run outside. The exception can be viewed within the log file found in the UDUMP directory.
    Solution
    Run the following code to confirm obtaining available __printers can not be done...__
    This is the code to create the Java Stored Procedure
    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "ListPrinters" AS
    import javax.print.*;
    public class ListPrinters {
    public static String AvailablePrinters(){
    String strList;
    PrintService[] pservices =PrintServiceLookup.lookupPrintServices(null,null);
    if (pservices.length > 0 )
    strList = pservices[0].getName();
    else
    strList = "No printers found";
    return strList;
    public static String listprinters() throws Exception {
    String listofprinters;
    try {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) sm.checkPrintJobAccess();
    catch (SecurityException ex) {
    System.err.println("Sorry. Printing is not allowed.");
    listofprinters = AvailablePrinters();
    return listofprinters;
    This is the PL/SQL Wrapper
    CREATE OR REPLACE FUNCTION Get_Printer_Test RETURN VARCHAR2 IS
    LANGUAGE JAVA
    NAME 'ListPrinters.listprinters() return String';
    This executes the code
    SQL> SELECT Get_Printer_Test FROM DUAL;
    GET_PRINTER_TEST
    No printers found
    This is the output found in the trace file in the UDUMP directory
    *** SESSION ID:(144.28) 2006-07-08 09:02:25.518
    Sorry. Printing is not allowed.

  • Printing HTML with Java Printing Service(JDK1.4 beta)

    Hi there!
    I'm currently checking out the new Java Printing Service (JPS) in the new JDK1.4 beta. This looks like a very promising printing API, with amongst others printer discovery and support for MIME types - but I have some problems with printing HTML displayed in a JEditorPane.
    I'm developing an application that should let the user edit a (HTML)document displayed in a JEditorPane and the print this document to a printer. I have understood that this should be peace-of-cake using the JPS which has pre-defined HTML DocFlavor amongst others, in fact here is what Eric Armstrong says on Javaworld (http://www.javaworld.com/javaone01/j1-01-coolapis.html):
    "With JPS, data formats are specified using MIME types, for example: image/jpeg, text/plain, and text/html. Even better, the API includes a formatting engine that understands HTML, and an engine that, given a document that implements the Printable or Pageable interface, generates PostScript. The HTML formatting engine looks particularly valuable given the prevalence of XML data storage. You only need to set up an XSLT (eXtensible Stylesheet Language Transformation) stylesheet, use it to convert the XML data to HTML, and send the result to the printer."
    After one week of reasearch I have not been able to do what Armstrong describes; print a String that contains text of MIME type text/html.
    I have checked the supported MIMI types of the Print Service returned by PrintServiceLookup.lookupDefaultPrintService(). This is the result:
    DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(new Copies(2));
    PrintService[] service = PrintServiceLookup.lookupPrintServices(flavor,aset);
    if (service.length > 0) {
    System.out.println("Selected printer " + service[0].getName());
    DocFlavor[] flavors = service[0].getSupportedDocFlavors();
    for (int i = 0;i<flavors.length;i++) {
    System.out.println("Flavor "+i+": "+flavors.toString());
    Selected printer \\MUNIN-SERVER\HP LaserJet 2100 Series PCL 6
    Flavor 0: image/gif; class="[B"
    Flavor 1: image/gif; class="java.io.InputStream"
    Flavor 2: image/gif; class="java.net.URL"
    Flavor 3: image/jpeg; class="[B"
    Flavor 4: image/jpeg; class="java.io.InputStream"
    Flavor 5: image/jpeg; class="java.net.URL"
    Flavor 6: image/png; class="[B"
    Flavor 7: image/png; class="java.io.InputStream"
    Flavor 8: image/png; class="java.net.URL"
    Flavor 9: application/x-java-jvm-local-objectref; class="java.awt.print.Pageable"
    Flavor 10: application/x-java-jvm-local-objectref; class="java.awt.print.Printable"
    As you can see there is no support for text/html here.
    If anyone has a clue to what I'm missing here or any other (elegant, simple) way to print the contents of a JEditorPane, please speak up!
    Reply to: [email protected] or [email protected] or here in this forum

    Since you have 'printable' as one of your flavors, try this using a JTextPane (assuming you can dump your HTML into a JTextPane, which shouldn't be a big problem)...
    1. Have your JTextPane implement Printable
    ie. something like this:
    public class FormattedDocument extends JTextPane implements Printable 2. Read your HTML into the associated doc in the text pane.
    3. Implement the printable interface, since you have it as one of your available flavors (I'd imagine everybody has printable in their available flavors). Something like this:
    public int print(Graphics g, PageFormat pf, int pageIndex) {
            Graphics2D g2 = (Graphics2D) g;
            g2.translate((int)pf.getImageableX(), (int)pf.getImageableY());
            g2.setClip(0, 0, (int)pf.getImageableWidth(), (int)pf.getImageableHeight()); 
            if (pageIndex == 0)
                setupPrintView(pf);
            if (!pv.paintPage(g2, pageIndex))
                return NO_SUCH_PAGE;
            return PAGE_EXISTS;
        }Here's my setupPrintView function, which is executed once on page 0 (which still needs some polishing in case I want to start from page 5). It sets up a 'print view' class based on the root view of the document. PrintView class follows...
    public void setupPrintView(PageFormat pf) {
    View root = this.getUI().getRootView(this);
            pv = new PrintView(this.getStyledDocument().getDefaultRootElement(), root,
                               (int)pf.getImageableWidth(), (int)pf.getImageableHeight());Note of obvious: 'pv' is of type PrintView.
    Here's my PrintView class that paints your text pane line by line, a page at a time, until there is no more.
    class PrintView extends BoxView
        public PrintView(Element elem, View root, int w, int h) {
            super(elem, Y_AXIS);
            setParent(root);
            setSize(w, h);
            layout(w, h);
        public boolean paintPage(Graphics2D g2, int pageIndex) {
            int viewIndex = getTopOfViewIndex(pageIndex);
            if (viewIndex == -1) return false;
            int maxY = getHeight();
            Rectangle rc = new Rectangle();
            int fillCounter = 0;
            int Ytotal = 0;
            for (int k = viewIndex; k < getViewCount(); k++) {
                rc.x = 0;
                rc.y = Ytotal;
                rc.width = getSpan(X_AXIS, k);
                rc.height = getSpan(Y_AXIS, k);
                if (Ytotal + getSpan(Y_AXIS, k) > maxY) break;
                paintChild(g2, rc, k);
                Ytotal += getSpan(Y_AXIS, k);
            return true;
    // find top of page for a given page number
        private int getTopOfViewIndex(int pageNumber) {
            int pageHeight = getHeight() * pageNumber;
            for (int k = 0; k < getViewCount(); k++)
                if (getOffset(Y_AXIS, k) >= pageHeight) return k;
            return -1;
    }That's my 2 cents. Any questions?

  • Java Print Service - PDF

    I want to use the Java Print Service(JPS) API to programatically send
    PDF files to a printer. I need to send these files to the printer
    without any user intervention.
    At present i am trying to print on HP Laserjet 5100 series.
    I am able to print text files,Images (Jpeg) but have not been successfull in printing
    PDF files.
    DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
    DocFlavor flavor =new DocFlavor("application/pdf", "java.io.InputStream");
    The error I recieve is "Invalid Flavor". I have tried sending the PDF to the
    printer using a Document Flavor of INPUT_STREAM.AUTOSENSE.
    I also tried with
    DocFlavor flavor =new DocFlavor("application/octet-stream", "java.io.InputStream");
    When I do
    this the PDF file gets sent to the printer but what actually gets
    printed is garbage (control characters, overtyping, etc...).
    It appears the printer does not directly support PDF printing. The
    interesting thing is that I if I bring up a PDF file using Adobe Reader
    and press the Print button the file does get printed successfully!
    Can someone help me explain why Adobe Reader can print the file
    successfully but I am unable to do it programattically? Can someone
    suggest a different approach to take?.
    Regards,
    Raghu

    I suspect that it is because Adobe Reader isn't trying to print using the printer's non-existent PDF support. It is probably just sending generic image data to the printer as you would if you were printing Java 2D graphics using JPS.
    - Tomas

  • Turn off banner within Java Print Service API

    I have web services running on JBoss 4.0.5, which is running on IBM AIX 5.
    The issue I have is anytime I try to print something through Java Print Service within web services, there is always a banner, even though banner property is set to "never" on the print queue with AIX smitty. The bad news is that property value can be overwritten by applications, or by command line options with lp or lpr commands.
    Couldn't find any way or any attribute avaiable in Print Service API to diable banner printing. Currently only default attributes are used in document printing.
    Any help would be greatly appriciated!

    fermar84 wrote:
    Thanks for answering,
    Yes i totally agree with you. There is a per device basis. However you could think (and here i am letting my imagination fly) about categorizing devices, lets say all the digital cameras. Although it would still be per-device basis, some would have common commands like turn on, or turn off. Don't you think so?
    Now lets take a simple example, can a Java program turn off the computer where its running?
    Thanks in advance,
    FernandoDo I think all digital cameras expose an "on/off" API? No, I don't. Some may, they all may, but that's in no way a Java issue.
    Can a Java program turn off a PC? No. It can call native code to do so, but then it isn't Java doing the work. All of what you're talking about is very much platform-specific, and that's where Java is generally it's weakest

  • Does Java Access Bridge supports Java 6?

    Does Java Access Bridge support Java 6?
    Also where can I find 2.0.4 (Beta), the following link does not work -
    http://java.sun.com/developer/earlyAccess/accessbridge/
    thanks,
    sachin.

    Our company develops an applet that supports Jaws via the Java Access Bridge v.2.01. We've had no problems with JRE 1.6. However, Jaws does not read the accessible names when I tried JRE 1.7. It behaves as if the access bridge is broken. I reverted back to JRE 1.6.0_20 and it works fine again. I reported this to Freedom Scientific but they just said, "you will need to contact the Sun support team to determine the latest version of the JRE recognized by the Accessibility Bridge." They don't seem too concerned that their product may not work for many people in the near future.

  • Today i purchased exportpdf. when converting from pdf to word doc, the text does not show up on word doc. what to do?

    when exporting pdf into a word doc the text does not show up on new doc. what to do?

    Hi hamsa142,
    Is this problem specific to one file, or does it happen with any file that you convert to PDF? How was the PDF created (using what application)?
    For starters you may want to disable OCR as described in this document: How to disable Optical Character Recognition (O... | Adobe Community.
    Please let us know how it goes.
    Best,
    Sara

  • How do I get in contact with apple print services support Australia when my Print Order (book) keeps being cancelled (for no known reason)

    How do I get in contact with apple print services support Australia when my Print Order (book) keeps being cancelled (for no known reason)

    Portables that will not Power on.
    Try another power outlet.
    http://support.apple.com/kb/TS1365
    Go step by step.
    Note: Steps 5 and 6
    Best.

  • Java print services  UnsatisfiedLinkError

    i'm try to run the program given with java print services guide
    i.e PrintPS.java...
    and got this error...any idea what went wrong...
    Exception in thread "main" java.lang.UnsatisfiedLinkError: getDefaultPrinterName
    at sun.print.Win32PrintServiceLookup.getDefaultPrinterName(Native Method
    at sun.print.Win32PrintServiceLookup.getDefaultPrintService(Win32PrintSe
    rviceLookup.java:198)
    at sun.print.Win32PrintServiceLookup.getPrintServices(Win32PrintServiceL
    ookup.java:61)
    at sun.print.Win32PrintServiceLookup.getPrintServices(Win32PrintServiceL
    ookup.java:157)
    at javax.print.PrintServiceLookup.getServices(PrintServiceLookup.java:35
    9)
    at javax.print.PrintServiceLookup.lookupPrintServices(PrintServiceLookup
    .java:105

    I also have this same problem. Please help me out when you got the solution. my email address: [email protected]
    Thanks.

  • How to open pdf or word doc or notpad file in flex

    hai friends,
           how to open pdf or word doc or notpad file in flex. i am doing flexcoldfusion project. now i reterive data(notpad or worddoc or pdf file path) from database using coldfusion.now i want to open that file content .if i reterive notpad file .that will show in notpad. if it is possible. give example.
    regards,
    welcomecanv

    Hi WelcomeCan,
    Try this...
    var urlRequest:URLRequest = new URLRequest();
        urlRequest.url = "http://www.yourdomain.com/notepad.txt";
        //urlRequest.url = "http://www.yourdomain.com/FlexComp.pdf";
        navigateToURL(urlRequest,_blank);
    Thanks,
    Bhasker Chari

  • Need help to add the words in a text file to an arraylist

    I am new to java and I really need some help for my project.I want to add the words of a text file to an arraylist. The text file consist of words and the following set of punctuation marks {, . ; : } and spaces.
    thanks in advance :-)

    I/O: [http://java.sun.com/docs/books/tutorial/essential/io/index.html]
    lists and other collections: [http://java.sun.com/docs/books/tutorial/collections/index.html]

  • To get  a  word in the text  file

    Hi,
    I m beginner to java.
    HOw i get a word in the text file.
    I used this code, it is only display the all sentence which are available in the text file.
    But , I need to print particular word (if it is available in that text file)
    package com.beryl;
    import java.io.*;
    class FileReadTest {
    public static void main (String[] args) {
         FileReadTest f = new FileReadTest();
    f.readMyFile();
    void readMyFile() {
         BufferedReader dis =null;
    String record = null;
    int recCount = 0;
    try {
    File f = new File("E:/hello/abc.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis
    = new BufferedReader(new InputStreamReader(bis));
    while ( (record=dis.readLine()) != null ) {
    recCount++;
    System.out.println(recCount + ": " + record);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
         try {
    dis.close();
         } catch (IOException ioe) {
    Thanks & Regards,
    kumar

    I used this code, it is only display the all
    sentence which are available in the text file.
    But , I need to print particular word (if it
    is available in that text file)if
    String.indexOf()

  • Word count in text file

    Hi,
    I am trying to count word in my text file by using the Java code. Even though i am error in the code and don't know what sintaks to use. For example:
    I have
    school 4
    bus 3
    student 5
    in a.txt
    Another text file
    bus 2
    school 2
    in b.txt
    I want to display in new text file: c.txt
    school 6 4 : a.txt 2 : b.txt
    bus 5 3 : a.txt 2 : b.txt
    student 5 5 : a.txt
    Could you please advise,what sintak that i could use??
    Thanks you..

    Use StringTokenizer object and HashMap Object
    example
    String str = (your text readed from file A)
    StringTokinzed token = new StringTokinzed(str);
    while (token.hasMoreTokens()) {
    String word = token.nextToken()
    Integer i = (Integer) hashmap.get(word);
    if (i==null) {
    i = new Integer(1);
    }else
    i++;
    hashmap.put(word,i);
    same code for B file
    iterate through the hasmap and print all word with the count

  • Replace/cut part of words from a text file.

    Hello Hello everyone, I have a quick question. I have my text file that contains also words like ... let's say abc1, abc2 and so on, and I need to cut the c from the word, I need ab1, ab2.
    Here is what I have started:
    import java.util.*;
    import java.io.*;
    public class test
            Vector<String> x = new Vector<String>();
    public mergefiles() throws IOException
            readAdd("test.txt");
            write("testout.txt");    
    private void readAdd(String name) throws IOException
            BufferedReader reader = new BufferedReader(new FileReader(name));
            String line,all=new String();
            while ((line = reader.readLine ()) != null)
                    all+=line+'\n';
            reader.close ();
            int posX=all.indexOf("X"); // x being like first word of the text file
              if (all.length()-posX>0)
                   String between=all.substring(posX+3,all.length());
                   StringTokenizer st=new StringTokenizer(between," \n");
    private void write(String name) throws IOException
            BufferedWriter writer = new BufferedWriter(new FileWriter(name));
            String s=new String();
             if (x.size()>0)
                  s+="X"+'\n';
             s+='\n';
             writer.write(s);
            writer.close();
    public static void main(String[] args) throws IOException
            new test();
    }I am new to Java and I would really appreciate if you would be patient with me.
    Thank you!

    I have tried in readAdd method something like:
    int posX=all.indexOf("X"); // x being like first word of the text file
              if (all.length()-posX>0)
                   string.replace("ab1","abc1");
              }     but still doesn't work, and this is not a really good ideea, in case that I have to replace 1000 of abci ...I should use a for in my write method:
    String[] s=new String[2];
    for(int i=0;i<word.length;i++)
                   BufferedWriter writer = new BufferedWriter(new FileWriter(testout.substring(0, testout.lastIndexOf("."))+(i+1)+".txt"));
                       writer.write(s);
              writer.close();
    But I not really sure if this is ok! Right now nothing is working
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • Blue screen of death, can't boot recovery or from external disk.

    Hello Guys. I have a very wiered problem with my 15 Macbook Pro early 2011 (thunderbolt), latest version of mountain lion (10.8.4?). The computer does boot but won't show up the login screen. I've tried  to boot in recovery mode, but as soon as recov

  • Digital Voice Suddenly Not Working

    I recently moved into a new home and had FiOS installed. Everything worked well for about a month, but then my landline seemed to stop functioning. I can't get a dial tone on either of the phones I've tried (they'll display "No Line" or occasionally

  • Getting Active Directory Users in UCM User Admin - Users Tab

    Hello All We have integrated WLS with our Active Directory. And we are getting all the active directory users under Security Realms >myrealm >Users and Groups tab in WLS Console. We are also able to login to webcenter spaces and Content server using

  • Client exception

    I get this run time error when I try to invoke create method in container managed Entity Bean. This error acured only when I unmark the options: create table on deploy and delete table on undeploy at the deploytool. is any one can help me. org.omg.CO

  • How can i install Pages on my IPad air?

    I've downloaded Pages from the App-store on the IPad Air, but I can't get it installed! Anyone out there who can help me? What went wrong?