Can one load an RTF file with pictures into a TextArea? How?

I have a Help file in RTF format which contains screenshots. I would like to be able to load it upon startup of the app and display it in a TextArea. Has anyone an example, a code snippet?

Won’ work with the standard textArea. Use an HTML viewer or pick up the Formatted Text Control from BKeeney Software

Which platform?
On Mac we use Cocoa methods to load more than the usual things.

[quote=57666:@Christian Schmitz]Which platform?
On Mac we use Cocoa methods to load more than the usual things.[/quote]
OSX Cocoa. I saw there are MBS functions - however, I am struggling with how to use it - as usual, I need an example…

I’m trying to do this, but it throws an exception at TextinputStream.Open …

[code] Dim f As FolderItem
f = App.ExecutableFile.Parent.Parent.Child(“Resources”).Child(“HelpNoPix.rtfd”)

If f <> Nil Then
If f.Exists Then
Dim oFile As String
Try
Dim ts As TextInputStream = TextInputStream.Open(f)
oFile = ts.ReadAll

    Catch e As IOException
      MsgBox "Something went wrong when opening the Help File"
    End Try
    
    Me.StyledText.RTFDataMBS = oFile
    
  End If
End If

End If[/code]

For a cross platform solution you can take a look at our Formatted Text Control http://www.bkeeney.com/formatted-text-control/

I stumbled into the same problem and solved it :

  • Load the RTF in Open Office
  • Save as HTML

Then I use an HTMLViewer. The great thing is that it is cross platform as well.

Yes, I’m using it on other apps. But here I just wanted to create a little help page with pictures for a utility. It seemed overkill to me to add the whole FTC to it and I hoped that there was something smaller to achieve the goal. For now I just skipped the pictures and stayed with built in rtf functionality.

Hi Michael,
Could you provide some code showing how to do this?
Thanks.
Lennox

Then why use RTF? Why not HTML?

What do you use to create the HTML files then?

Just told you : use Open Office to load your RTF file and save it to HTML. On Windows I use Word.

Then I often use Kompozer (from kompozer.net) to touch the html if needed.

I just thought about another approach for a small help though : hard code the text and pictures onto a scrollable container control, within the page. Did not do it yet, but seems feasible if the text is not too long.

Hmm - I just noticed, that those rtf files I created using TextEdit on OSX, are actually folders, storing the pictures inside. No wonder my above code crashed.

For future use I’m about to look into MBS DynaPDF. It comes with some Viewer examples. It would be nice to create PDF from some easy and familiar Word processor and then have an equally easy way to display them from one’s apps. (And not externally in Acrobat and the like).

You can do it like this:

dim file as FolderItem = SpecialFolder.Desktop.Child("test.rtfd") dim n as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithPath(file) dim t as NSTextViewMBS = TextArea1.NSTextViewMBS t.textStorage.setAttributedString(n)

Simply provide folderitem for rtfd file and it’s loaded.

[quote=57710:@Michel Bujardet]Just told you : use Open Office to load your RTF file and save it to HTML. On Windows I use Word.
… .[/quote]
Hm - it must have come in when I answered to Bob, so I overlooked it. Thanks anyway!
In my experience rtf from Word is mostly not usable in other apps, especially not in Xojo.

Right now I do the typing and basic formatting in TextEdit on OSX. Then I copy/paste it to a little xojo app’s TextArea from where I save it as a rtf file. Now that it is in a Xojo-safe format, I put the file in the resource folder and read it to the textarea of my utility, on app startup.

Gosh…

[quote=57720:@Christian Schmitz]You can do it like this:

dim file as FolderItem = SpecialFolder.Desktop.Child("test.rtfd") dim n as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithPath(file) dim t as NSTextViewMBS = TextArea1.NSTextViewMBS t.textStorage.setAttributedString(n)

Simply provide folderitem for rtfd file and it’s loaded.[/quote]
Yes! Great, this is exactly what I wanted.
MBS plugins makes my day. (Once again)

Thanks Christian!

Well, for every case the right tool:

HTMLviewer is a good choice for showing static formatted content with images and links.
Textarea with Cocoa classes is good to overcome some limits in Textarea control.
And FTC is great full feature text processor if you need one in your app.

RapidWeaver.

I have a function available to convert RTF to and from HTC :slight_smile:

Don’t forget that Formatted Text Control will export to HTML so it’s easy to whip up something in RTF (with images) and then export to HTML (even the demo app does this).