Convert RTF to Text Using Same Library as SPS

Questions about and code samples for automation process code snippets within Select.
Post Reply
kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

Convert RTF to Text Using Same Library as SPS

Post by kkirkfield » Sat Jul 21, 2018 2:05 pm

If I get the text from Order.Title.Commitments.Requirements.Text, it is a string in RTF format. How can I convert this string to plain text using the same library or methods SPS uses?

BobRichards
Posts: 1006
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Convert RTF to Text Using Same Library as SPS

Post by BobRichards » Mon Jul 23, 2018 10:37 am

Our RTF to text methods are not public. We decode the mangled RTF string directly since on server packages, RichTextBox controls are not available to perform this function.
Bob Richards, Software Developer, SoftPro

kkirkfield
Posts: 27
Joined: Tue Jun 28, 2016 2:26 pm

Re: Convert RTF to Text Using Same Library as SPS

Post by kkirkfield » Mon Jul 23, 2018 1:22 pm

Thanks Bob, I didn't realize I could do this with a built-in control. WinForms is in the GAC, so I'm able to use the RichTextBox from IronPython to achieve good results. Here is a working example.

Code: Select all

import clr
clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import RichTextBox

rtb = RichTextBox()
rtb.Rtf = Context.Title.Commitments[0].Requirements[0].Text
Context.RelatedOrders = rtb.Text

BobRichards
Posts: 1006
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Convert RTF to Text Using Same Library as SPS

Post by BobRichards » Mon Jul 23, 2018 2:24 pm

Yep. That's what I would do. Be careful that you don't create lots of instances of the control since that has the potential to drastically slow things down. You certainly would not want to do this in a Custom Order Rule.
Bob Richards, Software Developer, SoftPro

Post Reply