Printing RTF files in Java

Hi,
I have a java application (No GUI) that needs to print an RTF file. Could any one provide me links to tutorial/sample codes for doing this?
Thanks a lot,
Vaishali

Look at http://www.fawcette.com/javapro/2002_12/online/print_kgauthier_12_10_02/default_pf.aspx. They provide an utility class which basically lets you do this in 1 line, by creating a JEditorPane with your document and passing it to a method there.

Similar Messages

  • 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

  • Printing problem with RTF file in java

    Hi,
    i actually got code to print the RTF doc using java, it works fine if we give small content (some text), but throws error 'java.io.ioException: Too many close-groups in RTF " when actual bill content is pass.
    Thanks in advance

    Can you please share the code to print the RTF file using java API

  • Print RTF file within app

    Hi
    Is it possible to print an rtf file from within java app without actually viewing the file on screen? I don`t want to display the file in a jtextpane or jeditorpane. Simply want to print the file like you can with a straight text file.
    Or, is there are a command line switch to print a rtf file? through ms word?
    Any help would be appreciated.
    Thanks
    Kelly

    printing RTF files from java is amazingly hard. if not impossible.
    (just what you wanted to hear)
    basically, rtf support in java is pathetic.
    in my case, i had to create an actual RTF file in ms word and save it.
    i then opened it in notepad so that i could see all the control codes.
    then i cut and pasted each section of the document template so that each bit was a string constant in java. the bits that i wanted to add i generated in code the normal way.
    then i stuck all the bits back together again in one string and sent that off to a data stream. (to answer your question, it never went to the screen, just to the data stream)
    its a bloody stupid way of doing rtf, but it was the only way to get it to work without having to go through and figure and implement out all the rtf codes yourself.

  • Creation of .RTF file in java

    Hi,
    I want to create/edit .RTF file through java application. In my RTF file, I should be able to edit data(formatting), inserting tables. This is already done. Now I want to create chart (like pie-chart) using java. I searched the net for the last couple of days but I couldn't get the proper help. I can do that in SWING but its of no use.
    can anyone help me in this?
    Thanks & Regards,
    mrP

    Hi,
    Can someone please point me in the right direction? I'm trying to create an RTF file from data in a database, so I have no need to use JTextPanel or any GUI components. I've been trying to use the RTFEditorkit with a DefaultStyledDocument, but can only manage to insert one line into the document(!) Does anyone have any suggestions or examples that would explain how to do this?
    Any ideas would be appreciated.
    Thanks in advance,
    Gillian

  • How To Read RTF file in JAVA?  Using  iText?

    How To Read RTF file in JAVA?  Using  iText?.....
    import java.io.*;
    import com.lowagie.text.*;
    import com.lowagie.text.rtf.*;
    public class RTF3 {
    public static void main(String[] args) {
    // System.out.println("This example generate a RTF file name Sample.rtf");
    // Create Document object
    Document myDoc = new Document();
    try {
    // Create writer to listen document object
    // and directs RTF Stream to the file Sample.rtf
    RtfWriter2.getInstance(myDoc, new FileOutputStream("Sample.rtf"));
    // open the document object
    myDoc.open();
    // Create a paragraph
         Paragraph p = new Paragraph();
         p.add("Helloworld in Rtf file..amazing isn't");
         // Add the paragraph to document object
    myDoc.add(p);
    catch(Exception e) {
    System.out.println(e);
    //close the document
    myDoc.close();
    Exception in thread "main" java.lang.NoSuchMethodError: com.lowagie.text.Rectangle.width()F
         at com.lowagie.text.rtf.document.RtfPageSetting.rectEquals(RtfPageSetting.java:433)
         at com.lowagie.text.rtf.document.RtfPageSetting.guessFormat(RtfPageSetting.java:362)
         at com.lowagie.text.rtf.document.RtfPageSetting.setPageSize(RtfPageSetting.java:341)
         at com.lowagie.text.rtf.RtfWriter2.setPageSize(RtfWriter2.java:248)
         at com.lowagie.text.Document.open(Unknown Source)
         at view.RTF3.main(RTF3.java:23)
    CAN you HELP me?

    import com.lowagie.text.Document;
    import com.lowagie.text.rtf.parser.RtfParser;
    import java.io.FileInputStream;
    String inputFile = "sample.rtf";
    Document document = new Document();
    document.open();
    RtfParser parser = new RtfParser(null);
    parser.convertRtfDocument(new FileInputStream(inputFile), document);

  • How to print PDF files using java print API

    Hi,
    I was goign throw lot of discusion and reading lot of forums related to print pdf files using java api. but nothing seems to be working for me. Can any one tell me how to print pdf files using java api.
    Thanks in advance

    Mike,
    Can't seem to get hold of the example described in your reply below. If you could let us have the URL to get then it would be great.
    My GUI application creates a pdf document which I need to print. I want to achieve this using the standard Java class PrinterJob (no 3rd party APIs I'm afraid, commercial restraints etc ..). I had a stab at it using the following code. When executed I get the pretty printer dialog then when I click ok to print, nothing happens!
    boolean showPrintDialog=true;
    PrinterJob printJob = PrinterJob.getPrinterJob ();
    printJob.setJobName ("Contract.pdf");
    try {
    if (showPrintDialog) {
    if (printJob.printDialog()) {
    printJob.print();
    else
    printJob.print ();
    } catch (Exception PrintException) {
                   PrintException.printStackTrace();
    Thank you and a happy new year.
    Cheers,
    Chris

  • Directly Printing RTF document using java

    Hi,
    can we directly print RTF document using java, without giving any preview or any other screen in between.
    Actually we created inventory system, in which when user create any sale information, it should print the bill for the same with single button click.
    Any sample code or help will be highly appreciated
    Thanks in advance

    Hi,
    can we directly print RTF document using java, without giving any preview or any other screen in between.
    Actually we created inventory system, in which when user create any sale information, it should print the bill for the same with single button click.
    Any sample code or help will be highly appreciated
    Thanks in advance

  • Reading an RTF file in Java

    Hi,
    Can someone tell me how can we read the data from an .rtf files like we do with text files in Java.
    I have seen solutions using Swing rtfeditor etc.. But I just need to read the data, I do not want to open rtf page.
    Any help would be appreciated.
    KK

    If you are not to "read" but to obtain bytes then you can modify this:
    //try{
      InputStream stream = new FileInputStream("cc.rtf");//file name is arbitrary
                                                                             //or BufferedInputStream can be used
       int n=0;
    while((n=stream.read())!=-1){
                System.out.print(Integer.toString(n));
                System.out.print(" ");
        System.out.println();
       if(stream!=null) stream.close();
    //   catch(IOException ioe){
    //       throw ioe;
    //  }

  • 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

  • How to convert .doc file into .rtf file in Java?

    Hello All,
    I want to convert doc file into rtf format in java and for the same i am not getting any help so pls suggest some solution for that.
    Thanks and Regards
    only1Vinay

    MS-Word formats (DOC) are notorious for not being standardized from one version to another, so what ever you get will be version specific. If you must do the conversion, I suggest you do a MS-Script in Word to do it or one of the .Net languages. As stated the Word format from version to version is not standardized.

  • Merging Word (RTF) files in java

    Hey,
    I have a requirement to merge several word (or rft) files in java. The files are stored as blobs on the database. I had a look at http://poi.apache.org/hwpf/docoverview.html but that project seems to be parked at the moment. Has anybody any ideas?
    Thanks

    I agree its a bad idea but i was asked to look into
    its possibility.
    Previously it wasn't a problem as it was always one
    word file that was required
    for editing through the browser by the user but now
    they want to basically build a 'master doc' based on
    a bunch of business rules i.e. chose a subset of all
    their templates based on business rules at runtime.
    I pitched the idea of generating XSL:FO and adding
    conditionals around the various templates and then
    generating RTF from this. Storing the XSL:FO on the
    db but they didn't like that as they want to be able
    to add and modify new templates and then store these
    directly on the DB?!?!?!The way to address this is to find out what the real concerns are. Almost all stupid requirements are based upon some concern that is the result of a combination of fear and ignorance.
    So I would suggest you find out what the real concern is and address that specifically in your better design.
    Because the reality is that your solution is actually workable. Whereas the one you are being pushed towards will be very difficult and I fear result in an unmaintable mess.

  • How do Print TXT file in JAVA...?

    Dear sir,
    i have a program for printing txt file.... i tried below program..
    1. This code executed without exception... but its not printing.... when i saw print buffer, file is add but not printing
    2. Please help me out.... or give me some clue.... where i doing wrong....?
    Note:- am trying remote printing
              try {
                   FileInputStream fin = new FileInputStream(".\\file\\down.txt");
                   // set up attributes set
                   PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
                   pras.add(new Copies(1)); // number of copies
                   // find the priner service
                   PrintService pss = PrintServiceLookup.lookupDefaultPrintService();
                   if (pss == null)
                        throw new RuntimeException("No printer services available.");
                   PrintService ps = pss;
                   System.out.println("Printing to " + ps);
                   // create print job
                   DocPrintJob job = ps.createPrintJob();
                   // print data
                   Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
                   // print it
                   job.print(doc, pras);
                   // close file
                   fin.close();
              } catch (IOException ie) {
                   ie.printStackTrace();
              } catch (PrintException pe) {
                   pe.printStackTrace();
              }Thank you
    boss134

    Hi ,
    i m asking if you got a solution for your problem ;
    i need solution to the same problem
    thx in advance

  • Printing TXT files with java

    Hi !!
    I�m trying to send the content of a .txt file to the default printer whith the next code; I read the file, and this method accept a String with the content I must print.
    // I�ve read the code in this forum, and I only made little changes....
    public void PrintFileString(String fileContent){
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    // getting PrintService
    PrintService service = PrintServiceLookup.lookupDefaultPrintService();
    if (service != null){
    System.out.println("Default Printer: " + service.getName());
    // Creating DocPrintJob
    DocPrintJob job = service.createPrintJob();
    try{
    // String to InputStream
    ByteArrayInputStream bais = new ByteArrayInputStream(fichero.getBytes());
    Doc doc = new SimpleDoc(bais,flavor,null);
    job.print(doc,aset);
    catch(Exception a){
    System.out.println(a + "error");
    I can print, in the default printer, but I need to change properties of printed document, like orientation, margins, number of copies, etc....
    Can I do it ??
    Really Thanks

    Please, help !!!
    I need to print a file in landscape mode.
    My code is:
    public class BasicPrint {
        public static void main(String[] args) {
            try {
                // Open the  file
                InputStream is = new BufferedInputStream(
                    new FileInputStream("c:\\diego.txt"));
                // Find the default service
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
                PrintService service = PrintServiceLookup.lookupDefaultPrintService();
                // put landscape mode
                PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                aset.add(OrientationRequested.LANDSCAPE);
                // Create the print job
                DocPrintJob job = service.createPrintJob();
                Doc doc = new SimpleDoc(is, flavor, null);
                try {
              job.print(doc, aset);
             } catch (PrintException e1) {
              e1.printStackTrace();
                // It is now safe to close the input stream
                is.close();
            } catch (IOException e) {
    }The text always is printed in the default orientation (portrait)
    I�ve tried with an image file (gif) changing the lines
      // Open the  file
      InputStream is = new BufferedInputStream(
                    new FileInputStream("c:\\diego.txt"));
      // Find the default service
                DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;by
      // Open the  file
      InputStream is = new BufferedInputStream(
                    new FileInputStream("c:\\image.gif"));
      // Find the default service
                DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;and works fine !!!
    but not with text. Why ???
    The line
    aset.add(new Copies(2));
    to print 2 copies, don�t work.
    Please, some help ???

  • Printing PDF files using java

    Is there a class or utility that already does this?
    Thx in advance.

    Do you want to create PDF files using Java? If so, there is a library available at http://www.lowagie.com/iText/docs.html Check out this site. There are many more similar PDFGEnerator tools that you can use..

Maybe you are looking for

  • What is the correct part number for the ac-charger for hp mini 110-1191eo (part vj213ea#uuw)?

    I need to find the correct part number for the ac-charger for hp mini 110-1191eo (part vj213ea#uuw). This question was solved. View Solution.

  • Help required to generate primary key sequence

    Hello All, I need your help in generating a sequence for primary key in my db table created using java dictionary project in my NWDS 7.3. The table column EMPL_ID is a primary and needs to be a sequence. The code in the JPA entity is as below. The un

  • Oracle Database suddenly very slow!

    Hello, After running our Oracle 10g instance on Red Hat Enterprise for more than two years without an itch it suddenly became extremely slow. A simple query that would take a few seconds now takes an hour to complete! It is not the network since the

  • WIN_API_UTILITY.INTERRUPTCHECK in 11g

    Hello! I have a problem after Forms Migration from 6i to 11g that the win_api_utility.interruptcheck doesn't work in 11g. After executing a sql select query that takes a long time, i need a solution to stop the query. In 6i we made it with win_api_ut

  • Employee Travel Expense Payments via ACH

    Hello, Currently we use SAP's T&E module and post the costs via an employee vendor record and then subsequently pay the vendor. Currently this is done by check. What we would like to do is pay via ACH and increase the frequency of payments. The issue