Storing RTFD document in database field

Hi to all,
I would like to save RTFD document in a sqlite blob field like binary data.
But the only way that I know is to use “Declare” and call “writeRTFDToFile” function than load the file from path and write the blob field,
as opposed to read using “readRTFDFromFile” function.
There is a more direct way by avoiding the creation of the file? Even through the MBS plugins?

Thanks

NSAttributedStringMBS Class has methods like RTFDData from range.

See

https://www.monkeybreadsoftware.net/class-nsattributedstringmbs.shtml

[quote=325797:@Christian Schmitz]NSAttributedStringMBS Class has methods like RTFDData from range.

See

https://www.monkeybreadsoftware.net/class-nsattributedstringmbs.shtml[/quote]
Hi Christian,
first of all thanks.
I’ve tried something like this in order to save :

dim t as new NSAttributedStringMBS

call t.initWithRTFD(MyTextArea.Text)

rs.Field(“myblob”).StringValue = t.RTFDFromRange(0,10000)
rs.Update

and this for read blob into textarea :

dim t as new NSAttributedStringMBS

call t.initWithRTFD(rs.Field(“my blob”).StringValue)

MyTextArea.Text = t.RTFDFromRange(0,10000)

but without result, there no example relative to RTFDData and probably is to hard for me to figure out how to do it.

Let me later make one.
How do you plan to store the embedded files?
Rtf is just styled text, but rtfd is with embedded images.

[quote=325844:@Christian Schmitz]Let me later make one.
How do you plan to store the embedded files?
Rtf is just styled text, but rtfd is with embedded images.[/quote]
Yes, with embedded image and I would like to store it in a sqlite blob field.

Luciano:

you may think that rtfd (Rich Text Format Directory) is not a file, but a folder holding a rtf item and one or more items (images).

More details here: Rich Text Format Directory - Wikipedia

That folder is in reality a bundle.

you can get RTFD from textarea to memory block like this:

// get RTFD to memoryblock dim n as NSTextViewMBS = TextArea1.NSTextViewMBS dim s as NSTextStorageMBS = n.textStorage dim m as MemoryBlock = s.RTFDFromRange

Your try, did strip styles and init new text with plaintext.

You read back like this:

[code]dim data as MemoryBlock // your data
dim v as NSTextViewMBS = TextArea1.NSTextViewMBS
dim s as NSTextStorageMBS = v.textStorage

dim n as new NSAttributedStringMBS

if n.initWithRTFD(data) then
s.setAttributedString(n)
end if[/code]

But for handling embedded images, you may need to use a file wrapper:

[code]// get RTFD to memoryblock
dim n as NSTextViewMBS = TextArea1.NSTextViewMBS
dim s as NSTextStorageMBS = n.textStorage
dim f as NSFileWrapperMBS = s.RTFDFileWrapperFromRange

dim Data as MemoryBlock = f.regularFileContents
[/code]
So the file wrapper than has the file content (RTF) and attached all the images, which you need to store separated.

You can also zip the Rtfd, then store it as base64.

Sorry for the delay but I had some trouble,
I want to thank Christian of his timely and effective help, probably without his support and his plugins I would not have been faithful all these years to Xojo.
Thanks to Michel and Emil for answers too.