I am a QT programmer and Cocoa is new for me. How can convert Rich Text Format(RTF text with images and hyper link) to HTML using cocoa under Mac OS X. I have rich text into a char type buffer.
Create an NSAttributedString instance with the RTF data. Walk the attribute ranges of the string (this includes the attachments / pictures) and translate to HTML (append the proper HTML to an NSMutableString) as you go. This lets you convert any attributes you'd like while leaving behind those you don't want.
A helpful NSAttributedString method would be -enumerateAttributesInRange:options:usingBlock:. Inside the block you can determine whether you want to handle or ignore a given attribute. See the Handling Attachments section for information regarding dealing with your images (considered an attachment in RTFD, just another attribute type for a "character" in the attributed string).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With