0

I am initialising an NSAttributedString with RTF and it works, in that I can see the text and attributes like font, size and weight are preserved.

NSMutableAttributedString* attributedRTFString = [NSMutableAttributedString.alloc initWithRTF:rtfContent documentAttributes:nil];

Some attributes, notably colour, are lost though. If I look at the RTF code I can see that those attributes are there (for example)…

{\*\htmltag72 </p>}
{\*\htmltag64 <p class=MsoNormal>}\htmlrtf {\htmlrtf0 
{\*\htmltag84 <b>}\htmlrtf {\b \htmlrtf0 
{\*\htmltag148 <span style='font-size:10.0pt;color:#5F5F5F'>}\htmlrtf {\htmlrtf0 
{\*\htmltag156 </span>}\htmlrtf }\htmlrtf0 
{\*\htmltag92 </b>}\htmlrtf }\htmlrtf0 
{\*\htmltag148 <span style='color:#1F497D'>}\htmlrtf {\htmlrtf0 
{\*\htmltag244 <o:p>}
{\*\htmltag252 </o:p>}
{\*\htmltag156 </span>}\htmlrtf }\htmlrtf0 \htmlrtf\par}\htmlrtf0
\htmlrtf \par
\htmlrtf0 

And I can see the colours in the original document.

How should I be opening RTF to preserve the formatting fully?

4
  • 1
    Quick question: If you create a NSAttributedString with some colors, and then convert it into RTF "Content", what are the colors tags? Also, that seems to be "htmlrt", not only "rtf", so that could be the reason on why there are differences? Commented Oct 11, 2022 at 7:44
  • Nope - opening that file in Text Edit doesn't show the colour either (fine in Word for Windows though, but not in Word for Mac). I can see that this isn't a problem that's been solved before - I'm going to have to write my own RTF tool. Commented Oct 15, 2022 at 12:03
  • it seems to be indeed a strange encoding: learn.microsoft.com/en-us/openspecs/exchange_server_protocols/… there was also a ticket lists.apple.com/archives/cocoa-dev/2014/Apr/msg00428.html Commented Oct 15, 2022 at 18:28
  • Yeah, I saw that. My own RTF library is coming on though - so hopefully I'll be able to sort this. Commented Oct 16, 2022 at 11:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.