Skip to content

nodoid/Plugin.RTFView

Repository files navigation

Plugin.RTFView

A cross-platform .NET MAUI control that renders Rich Text Format (RTF) content. It maps onto each platform's native text rendering, so RTF looks the way the platform intends:

Platform Backing view RTF rendering
iOS / Mac Catalyst UITextView Native NSAttributedString RTF parser
Windows RichEditBox (read-only) Native Document.SetText(FormatRtf, …)
Android TextView Built-in RTF → Spanned parser (no native RTF support)

Install

dotnet add package Plugin.RTFView

Targets net10.0-android, net10.0-ios, net10.0-maccatalyst, and net10.0-windows10.0.19041.0.

Setup

Register the handler in MauiProgram.cs:

using Plugin.RTFView;

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .UseRtfView();   // 👈 registers the RtfView handler

    return builder.Build();
}

Usage

XAML

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:rtf="clr-namespace:Plugin.RTFView;assembly=Plugin.RTFView"
             x:Class="MyApp.MainPage">

    <rtf:RtfView RtfSource="{Binding Document}" />

</ContentPage>

C#

using Plugin.RTFView;

var view = new RtfView
{
    RtfSource = @"{\rtf1\ansi {\colortbl;\red200\green0\blue0;}" +
                @"\b\fs28\cf1 Hello\b0  \i world\i0 !\par}"
};

API

Member Type Description
RtfView View The control.
RtfView.RtfSource string? The raw RTF markup to render. Bindable (RtfSourceProperty).
RtfViewBuilderExtensions.UseRtfView() extension Registers the handler on the MauiAppBuilder.

Setting RtfSource to null or an empty string clears the view. Malformed RTF is handled gracefully — the control logs a diagnostic and clears rather than throwing.

Supported RTF features

The native platforms (iOS/Mac/Windows) support the full breadth of their respective RTF engines. The Android parser is a pragmatic, dependency-free subset covering the common cases:

  • Groups { } with inherited state
  • Bold, italic, and underline (\b \i \ul + their 0 / none forms, \plain)
  • Foreground colour (\colortbl + \cf)
  • Background / highlight colour (\cb, \highlight)
  • Font family (\fonttbl + \f)
  • Font size (\fs, half-points → density-independent pixels)
  • Paragraph alignment (\ql \qc \qr \qj, \pard)
  • Paragraph and line breaks (\par, \line), tabs (\tab)
  • Escaped characters (\\ \{ \}), \'xx hex bytes, and \uN Unicode with \ucN fallback skipping

Not supported on Android

These do not map cleanly onto a TextView / Spanned model and degrade to plain (unstyled / unaligned) text:

  • Lists, tables
  • Embedded images / objects (\pict, \object)
  • Indents, line spacing, tab stops
  • Superscript / subscript

Building from source

dotnet build                       # all platforms
dotnet build -f net10.0-android    # a single target
dotnet pack -c Release             # produce the NuGet package (all four platforms)

The net10.0-windows target builds on macOS/Linux as well, via <EnableWindowsTargeting>true</EnableWindowsTargeting> (it compiles against the Windows reference assemblies).

Note: cross-compiled Windows binaries are not runtime-tested by the build. The Windows rendering path should still be smoke-tested on an actual Windows host before release.

License

DILLIGAF License v1.0 © 2026 Paul F. Johnson.

About

Cross-platform RTF viewer control for .NET MAUI (iOS, Mac Catalyst, Android, Windows)

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages