0
votes

Is there any way to programmatically insert RTF-formatted text into a PowerPoint TextFrame?

string myString = <some RTF formatted text>;

MyPlaceholder.TextFrame.TextRange.Text = myString;

This answer gets me close: Is it possible to insert pieces of RTF text into a Word document (.docx) using OpenXml?

But I am having trouble figuring out how to do this in PowerPoint rather than Word.

What I am trying to do is copy text from a RichEditBox in my application onto a PowerPoint slide and maintain font-color, format, etc. I am able to successfully bring the text into PowerPoint. I just can't bring in the formatting (such as font-color) with it.

Thanks.

1
Do you development UWP app?Nico Zhu - MSFT
Yes, it is a UWP app. ThanksMatt
UWP does not provide api to edit powerpoint file directly, you could search third part library to achieve this.Nico Zhu - MSFT
Sorry, Nico, I should have said that I am using an AppService to interface with PowerPoint from UWP. I then use VSTO to create the PowerPoint presentation. I have it correctly bringing text into the PowerPoint slides, but I am unable to get PowerPoint to bring in RTF-formatted text and maintain font-color, formatting, etc.) The text comes from a RichEditBox in my application and I need to duplicate the formatting in the RichEdit box on a PowerPoint slide.Matt

1 Answers

0
votes

I was finally able to accomplish this by saving from the RichEditBox to a stream using the following line of code and then writing to a file:

tempRichEditBox.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);

I then used this line to import the file into PowerPoint. The font color and formatting are maintained.

var rtfShape = PptSlide.Shapes.AddOLEObject(FileName: rtfFileName);