In the HtmlExportSettings there is no valid ImageExportMode that word is compatible with as it is not able to display Base64 encoded images.
Is there another ImageExportMode that is compatible?
OR
Is there a better solution to insert images from RichTextBox into a Microsoft word document? Possibly, create RadDocument from the word document I have and replace it in the RadDocument and do conversion to Microsoft word document?
Open to suggestions.
Hi Patrick,
This is possible, you can use the DocxFormatProvider to import the document, change it, and then export it back DOCX. Detailed information is available here: WPF RichTextBox - Using DocxFormatProvider.
I hope this helps. Should you have any other questions do not hesitate to ask.Can I add this docxFormatProvider similar to how you add HtmlFormatProvider in the xaml?
I've tried but it does not appear to work. It is not even an applicable item. My options are:
Below is my current HtmlDataProviderRtfDataProvider
HtmlDataProvider1
XamlDataProvider
TxtDataProvider
<telerik:HtmlDataProvider RichTextBox="{Binding ElementName=MyRadRichTextBox}" Html="{Binding MyText, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}"> <telerik:HtmlDataProvider.FormatProvider> <telerik:HtmlFormatProvider> <telerik:HtmlFormatProvider.ExportSettings> <telerik:HtmlExportSettings DocumentExportLevel="Fragment" ImageExportMode="UriSource" StyleRepositoryExportMode="DontExportStyles" StylesExportMode="Inline" ExportEmptyDocumentAsEmptyString="True" /> </telerik:HtmlFormatProvider.ExportSettings> </telerik:HtmlFormatProvider> </telerik:HtmlDataProvider.FormatProvider> </telerik:HtmlDataProvider>
Have a word document that acts as a template. This template will have {tokens} throughout it. These tokens will be replaced with:
- Text
- RichText (including tables, and images)
I need to be able to take the template and replace all tokens with the content from the corresponding dynamically generated RadRichTextBox.
Does RadDocument allow for find and replace of only text? Or can I find and replace tokens and replace with RICHText and export as docx?
Hi Patrick,
There is no data provider for the DOCX format since it cannot be bound to a string. With this format, you need to perform import/export in the code.
Yes, you can replace and insert any elements you want. More on this is available here: WPF RichTextBox - Search.
Let me know if you have additional questions.
So is there some way to bind a property to docx? So that I can access it in the view model?
From this forum post below I see this excerpt:
https://www.telerik.com/forums/binding-to-a-raddocument-inside-viewmodel
"Binding to DocX requires that the property must be of type byte []. Other than that, setting up the view model and the data provider is analogical to that for XamlDataProvider."
Can you give me a xaml example of that how that binding will appear?
Hi Patrick,
I have attached a project that shows this.
Let me know how this works for you.
I am not able to verify if it works because of the following 2 errors.
Severity Code Description Project File Line Suppression State
Error CS1061 'DocxDataProvider' does not contain a definition for 'RichTextBox' and no accessible extension method 'RichTextBox' accepting a first argument of type 'DocxDataProvider' could be found (are you missing a using directive or an assembly reference?)
Severity Code Description Project File Line Suppression State
Error CS0029 Cannot implicitly convert type 'Telerik.Windows.Documents.Flow.Model.RadFlowDocument' to 'Telerik.Windows.Documents.Model.RadDocument'
Hi Patrick,
I have tested the project and it works on my side (see attached). Which version are you using? It seems that the namspaces are wrong on your side. Have you changed them?
I am looking forward to your reply.
Using WPF and MVVM pattern...... I need to get all the XML that makes up content inside of a telerik:RadRichTextBox. I need a two way binding that works for the telerik:RadRichTextBox. Is this a possibility?
Example: User enters text inside of a radRichTextBox, it updates property in viewmodel and on button press, I can view and see all the XML that makes up the user entered content in the RadRichTextBox.
Hi Patrick,
This is possible, for example, you can use the DocumentContentChanged event and update the DOCX file. However, the export operation is expensive and this is not recommended. I would suggest creating a Save command to export the document and save it once all changes are made. Please note that the DOCX format is actually an archive that contains a lot of XML files. It cannot be exported to a single XML string. If you need a single string consider using RTF or XAML format providers.
Let me know if you have additional questions.
Now if I use RTF or XAML format providers, does telerik have converters or resources to get that into OPEN XML format?
Hi Patrick,
Yes, you can convert RadDocument to any of the supported formats using the format providers.
Another solution is to use the document processing library (supports the same format without XAML): WordsProcessing - Overview.
Let me know if I can be of further assistance.