Articles in this section

How to Export SfRichTextEditor Content to Word and PDF in .NET MAUI?

In this article, we’ll learn how to export rich text content from the Syncfusion .NET MAUI SfRichTextEditor to Word (DOCX) and PDF formats in a .NET MAUI application. We’ll cover the required packages, editor setup, export logic, and platform-specific file saving.

Why Export Rich Text Editor Content?

Exporting rich text content allows users to:

  • Save formatted notes, emails, or reports for offline use.
  • Share documents in universally accepted formats (Word, PDF).
  • Integrate document workflows in business, education, or productivity apps.

Use Cases:

  • Generating meeting minutes or reports from in-app editors
  • Exporting formatted emails or letters
  • Creating printable PDFs from user input

Step 1: Initialize the Rich Text Editor

Add the SfRichTextEditor to your XAML page and bind it to a ViewModel property for content editing.

XAML

<ContentPage>
   <ContentPage.BindingContext>
       <local:ViewModel/>
   </ContentPage.BindingContext>
   
   <editor:SfRichTextEditor x:Name="editor" HtmlText="{Binding HtmlText}" />
</ContentPage> 

ViewModel:

public class ViewModel : INotifyPropertyChanged
{
   public string HtmlText { get; set; } = "<p><strong>Hello,</strong> ...</p>"; // Your initial content
   // ...INotifyPropertyChanged implementation...
}

Step 2: Install Required NuGet Packages

Install the following Syncfusion packages from nuget.org in your MAUI project to export the content from SfRichTextEditor.

Step 3: Export Logic Using Syncfusion DocIO

Handle the export on button click by converting the editor’s HTML to a Word document, then to PDF if needed.

using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;

async void ExportDoc_Click(object sender, EventArgs e)
{
   string html = editor?.HtmlText ?? string.Empty;
   if (string.IsNullOrWhiteSpace(html)) return;

   using var htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html));
   using var wordDoc = new WordDocument(htmlStream, FormatType.Html);
   using var outStream = new MemoryStream();
   wordDoc.Save(outStream, FormatType.Docx);
   outStream.Position = 0;

   SaveService saveService = new();
   saveService.SaveAndView("Sample.docx", "application/msword", outStream);
}

async void ExportPdf_Click(object sender, EventArgs e)
{
   string html = editor?.HtmlText ?? string.Empty;
   if (string.IsNullOrWhiteSpace(html)) return;

   using var htmlStream = new MemoryStream(Encoding.UTF8.GetBytes(html));
   using var wordDoc = new WordDocument(htmlStream, FormatType.Html);
   using var renderer = new DocIORenderer();
   using PdfDocument pdfDoc = renderer.ConvertToPDF(wordDoc);
   using var outPdf = new MemoryStream();
   pdfDoc.Save(outPdf);
   outPdf.Position = 0;

   SaveService saveService = new();
   saveService.SaveAndView("Sample.pdf", "application/pdf", outPdf);
}    

Step 4: Add Platform-Specific Helper Files

Saving files requires platform-specific code. Download the helper files from this link and add them to your project as follows:

These files handle file saving and opening using each platform’s native APIs. Download the helper files from this link and add them into the mentioned project

Output:

Exporting MAUI SfRichTextEditor Contents to PDF and Word

Exported Word Document
Exported PDF Document

For more details, please refer to the project on GitHub sample.

Conclusion

I hope you found this helpful for exporting the rich text content from the Syncfusion SfRichTextEditor to Word and PDF in .NET MAUI, including all required packages and platform-specific file handling.

You can refer to our MAUI RichTextEditor feature tour page to learn about its other groundbreaking feature representations. For detailed guidance, refer to our .NET MAUI Rich Text Editor documentation.

For current customers, check out our .NET MAUI from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Chart and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied