You are not logged in.

Perry

Beginner

  • "Perry" is male
  • "Perry" started this thread

Posts: 40

Date of registration: Jan 15th 2011

Location: Sarasota, FL

Occupation: Cabinet Design

Hobbies: Programming

  • Send private message

1

Monday, July 22nd 2013, 6:14pm

Richtext box

I am trying to save a document from a richtext box with formatting & font designations which change a number of times throughout the document.

I know how to print it out from the richtext box.

But to save the file ... at least as .rtf
Are there any examples ... can I get any direction on this?


Perry

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

2

Thursday, August 1st 2013, 9:22pm

Hey there,

inspired by A1880

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Public Sub Form_Load()
   RichTextBox1.Text = ""
   RichTextBox1.appendText "Hey there,"
End Sub

Public Sub SaveRTF(RTB As RichTextBox, RTFFileName As String) 
  Dim fos As New java#io#FileOutputStream(New File(RTFFileName))
  Dim Doc As javax#swing#text#Document = RTB.Parent.getDocument 
  Dim kit As javax#swing#text#EditorKit = RTB.Parent.getEditorKit 
  Call kit.write(fos, Doc, 0, Len(RTB.Text))
  fos.close 
End Sub

Public Sub Command1_Click()
   SaveRTF(RichTextBox1,"c:\test.rtf")
End Sub


Please always post your solutions and enhancements...!


Dani

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Tuesday, August 6th 2013, 10:58pm

Quoted

with formatting & font designations which change a number of times throughout the document.


I looked at it again, I guess I missed your point!
The closest I get without using any 3rd party library is by saving the styled content to a html file!!

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
Public Sub SaveRTF(RTB As RichTextBox, RTFFileName As String) 
   Dim fos As New java#io#FileOutputStream(New File(RTFFileName))
   Dim doc As javax#swing#text#StyledDocument = RTB.Parent.getStyledDocument()
   Dim kit As New javax#swing#text#html#HTMLEditorKit
   kit.write(fos, doc, 0, doc.getLength())
   fos.close 
End Sub

Public Sub Command1_Click()
   SaveRTF(RichTextBox1,"c:\test.html")
End Sub


try the web looking for 'java save styleddocument'...

let us know what you come up with


Dani

Perry

Beginner

  • "Perry" is male
  • "Perry" started this thread

Posts: 40

Date of registration: Jan 15th 2011

Location: Sarasota, FL

Occupation: Cabinet Design

Hobbies: Programming

  • Send private message

4

Wednesday, August 7th 2013, 6:13pm

Thanks for your Response.
Though I didn't really want to save to HTML, your code may come in handy in the future.

What I came up with?
I needed to format barcodes into positions for label printing. No easy task if I can't save from the rich text control.

So I used the Wordpad utility from microsoft, made a bare bones nothing in it document, saved it, and reloaded it into a text editor. I also viewed it from a Hex editor so if there were any unprintable codes I could see them as well.
I figured out most of the meanings of the control codes, and the rules for placing them. I went back to Wordpad and entered a little text, in tabbed positions, then switched to the text editor and observed what differences the additions made.

Having said all that ... I write the RTF Programmatically, formatting the Label Sheet, all the tabbed positions, text, & barcodes using the Barcode font all in code from my program.

I also made a MS Word bare bones nothing in it document, thinking that I might use that instead ... OHHHH Boy. That thing scared the hooey out of me.

A MS Word nothing in it document, runs about 3 pages long with setup code and control code. I am sure that 3/4 of those are unnecessary, but which ... talk about bloatware.

Back to earth here, the Library program source I just posted, has my own implentation. A bit long to post the code here. But help yourself if you want to see mine.

Similar threads

Rate this thread
WoltLab Burning Board