Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: How to write to a rtf file in a specified font

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question How to write to a rtf file in a specified font

    I'm trying to write bar codes to a word file using a font. The problem is, what I usually use to write to files is the PrintWriter class, but it does not allow fonts.

     
                    File file = new File("path\\Test.rtf");
    		if(file.exists())
    			file.delete();
     
     
    		try {
    			file.createNewFile();
    		} catch (IOException e) {
     
    			JOptionPane.showMessageDialog(null, "Invalid path", "Error", JOptionPane.ERROR_MESSAGE);
    		}
     
    		FileWriter fw;
    		try {
    			fw = new FileWriter(file);
    		} catch (IOException e) { 
    			JOptionPane.showMessageDialog(null, "Invalid path", "Error", JOptionPane.ERROR_MESSAGE);
     
    			return;
    		}
    		PrintWriter output = new PrintWriter(fw);

    I use the output object to write to the file but there is not a PrintWriter.setFont() method


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write to a rtf file in a specified font

    I don't know that the java se classes write rtf control characters. There are third party packages that might do what you want.

    Have you done an Internet search?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to write to a rtf file in a specified font

    Ya, I've searched for it but all that came up were questions about how to set font to a .txt file.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write to a rtf file in a specified font

    Did you find any third party packages that write rtf files? Does the Apache project do it?

    EDIT: I just did a search and found this Java SE class: RTFEditorKit
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to write to a rtf file in a specified font

    The class doesn't look like it can print in a different font though, the only thing that shows up when you search the class summary page for font is in the nested classes, not any methods.
    RTFEditorKit (Java Platform SE 7 )

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write to a rtf file in a specified font

    It looks like the write() method will write out to a file the contents of a Document where the Font etc has been set.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to write to a rtf file in a specified font

    Thanks for the help, though now my boss wants me to print directly from the application

Similar Threads

  1. Replies: 6
    Last Post: March 16th, 2014, 08:03 PM
  2. Re: How to Change JTextArea font, font size and color
    By binokyo10 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 5th, 2012, 12:12 PM
  3. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 10:47 PM
  4. How to Change JTextArea font, font size and color
    By Flash in forum Java Code Snippets and Tutorials
    Replies: 4
    Last Post: July 8th, 2008, 01:45 PM

Tags for this Thread