RichTextBox and HTML
Hi all,
I experimented with RichTextBox controls and HTML.
It is possible to load HTML content into a RichTextBox. But I haven't succeeded in writing the RichTextBox to HTML.
Any ideas?
Greetings
A1880
I experimented with RichTextBox controls and HTML.
It is possible to load HTML content into a RichTextBox. But I haven't succeeded in writing the RichTextBox to HTML.
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Public Sub RichTextBox_LoadFileHtml(RTB As RichTextBox, aFileName As String) Dim fis As New FileInputStream(aFileName) Dim doc As New HTMLDocument Dim kit As New HTMLEditorKit doc.putProperty "IgnoreCharsetDirective", New Boolean(True) RTB.Parent.setEditorKit kit RTB.Parent.setDocument doc kit.read fis, doc, 0 fis.close End Sub Public Sub RichTextBox_SaveFileHtml(RTB As RichTextBox, aFileName As String) Dim fos As New FileOutputStream(New File(aFileName)) Dim doc As Document = RTB.Parent.getDocument Dim kit As HTMLEditorKit = Cast(RTB.Parent.getEditorKit, HTMLEditorKit) kit.Write fos, doc, 0,0 fos.close End Sub |
Any ideas?
Greetings
A1880
Well, my nearest idea is:
But it only saved one line.
Thanks,
klctal
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Public Sub SaveHTML Dim AftSave As String With CommonDialog1 .ShowSave If CommonDialog1.FileName="" Then Exit Sub 'Head AftSave="<html>"+chr(10)+"<head>"+chr(10)+"<title>Title</title>"+chr(10)+"</head>" 'Body AftSave=AftSave+chr(10)+"<body><p>"+RichTextBox1.Text+"</p></body></html>" SaveText2(AftSave,CommonDialog1.FileName) End With End Sub Public Sub SaveText2(Text As String, FileName As String) Dim File1 As VBFileHandler File1=Open(FileName) Write(File1,Text) End Sub |
But it only saved one line.
Thanks,
klctal
very easy with getEditorKitForContentType, but not whole compatible
Hi,
loading rtf or htm and writing rtf or htm
means converting between each other
easy going with the function JTextPane.getEditorKitForContentType
...but I also found Inconpatibilities:
if text is left-, middle- or rightaligned, the JTextpane does show it correctly but the Editorkit is not able to write it correctly, don't know why.
OlimilO
loading rtf or htm and writing rtf or htm
means converting between each other
easy going with the function JTextPane.getEditorKitForContentType
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Public Sub RichTextBox_SaveFileHTM(RTB As RichTextBox, aFileName As String) RichTextBox_SaveFile(RTB, aFileName, "text/html") End Sub Public Sub RichTextBox_SaveFile(RTB As RichTextBox, aFileName As String) 'default because RichText = rtf RichTextBox_SaveFile(RTB, aFileName, "text/rtf") End Sub Public Sub RichTextBox_SaveFile(RTB As RichTextBox, aFileName As String, contenttype As String) 'contenttype could either be ' "text/plain", or ' "text/html", or ' "text/rtf" Dim os As OutputStream = New FileOutputStream(aFileName) Dim pan As JTextPane = RTB.Parent Dim kit As EditorKit = pan.getEditorKitForContentType(contenttype) Dim doc As Document = pan.getDocument Dim wri As Writer = New OutputStreamWriter(os) kit.write(os, doc, 0, doc.getLength) os.flush os.close End Sub |
...but I also found Inconpatibilities:
if text is left-, middle- or rightaligned, the JTextpane does show it correctly but the Editorkit is not able to write it correctly, don't know why.
OlimilO
Similar threads
-
General topics, questions and discussions »-
Bug?
(Apr 21st 2009, 5:48pm)
-
General topics, questions and discussions »-
Save RTF File
(Jul 23rd 2009, 10:39am)
