# Drawing Rich Text String to Picture

**URL:** <https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780>\
**Category:** Getting Started\
**Created:** [March 18, 2019, 1:50am UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780 "2019-03-18T01:50:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edward\_Gilbert](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@Edward\_Gilbert](https://forum.xojo.com/u/Edward_Gilbert)\
**Post date:** [March 18, 2019, 1:50am UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/1 "2019-03-18T01:50:51Z")

</div>

How can I draw an imported Rich Text String to a canvas picture so that all of the formattings gets drawn to the canvas? Think of a Microsoft Word document that would have some words bold, some italic, so red font, some underlined font and so on.  
There is a specific reason I have to use draw an image to a Cavans with the formatted text, so I any help with this will be appreciated.

---

<div class="post-metadata">

**Author:** ![jim\_mckay](https://forum.xojo.com/user_avatar/forum.xojo.com/jim_mckay/32/905_2.png) [@jim\_mckay](https://forum.xojo.com/u/jim_mckay)\
**Post date:** [March 18, 2019, 2:40am UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/2 "2019-03-18T02:40:52Z")

</div>

Last time I tried, you could use an offscreen styled textarea to render RTF by setting myTextArea.StyledText.RTFData=theRTF Then “print” it to a graphics object using myTextArea.StyledTextPrinter(g,width).DrawBlock(x,y,height)

[https://documentation.xojo.com/api/printing/styledtextprinter.html#styledtextprinter-drawblock](https://documentation.xojo.com/api/printing/styledtextprinter.html#styledtextprinter-drawblock)

StyledText.RTFData doesn’t support everything, but it does a pretty good job.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [March 18, 2019, 2:42am UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/3 "2019-03-18T02:42:10Z")

</div>

I have found the best way is to iterate thru the styleruns, and using the inforation in each on, set the graphics object properties (font, color, bold etc), and use DrawString…

---

<div class="post-metadata">

**Author:** ![jim\_mckay](https://forum.xojo.com/user_avatar/forum.xojo.com/jim_mckay/32/905_2.png) [@jim\_mckay](https://forum.xojo.com/u/jim_mckay)\
**Post date:** [March 18, 2019, 2:43am UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/4 "2019-03-18T02:43:36Z")

</div>

That works too, and gives you more control of the final output.

---

<div class="post-metadata">

**Author:** ![Edward\_Gilbert](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@Edward\_Gilbert](https://forum.xojo.com/u/Edward_Gilbert)\
**Post date:** [March 18, 2019, 1:24pm UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/5 "2019-03-18T13:24:09Z")

</div>

Are there any examples of what the iteration would look like?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [March 18, 2019, 1:40pm UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/6 "2019-03-18T13:40:18Z")

</div>

[http://documentation.xojo.com/api/deprecated/textarea.html](http://documentation.xojo.com/api/deprecated/textarea.html)  
[http://documentation.xojo.com/api/text/stylerun.html](http://documentation.xojo.com/api/text/stylerun.html)

Example in the StyleRun page

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:35pm UTC](https://forum.xojo.com/t/drawing-rich-text-string-to-picture/47780/7 "2020-10-29T19:35:20Z")

</div>


