Search results

Add Google fonts

To use web fonts in RichTextEditor, it is not needed for the web fonts to be present in local machine. To add the web fonts to RichTextEditor, we need to refer the web font links and add the font names in the FontFamily property.

razor
controller.cs
@{
    string value = @"<p>
            The RichTextEditor control is WYSIWYG ('what you see is what you get') editor that provides the best user experience to create and update the content.
            Users can format their content using standard toolbar commands.
        </p>
        <p><b> Key features:</b></p>

        <ul>
            <li><p> Provides &lt; IFRAME &gt; and &lt; DIV &gt; modes </p></li>

            <li><p> Capable of handling markdown editing.</p></li>

            <li><p> Contains a modular library to load the necessary functionality on demand.</p></li>

            <li><p> Provides a fully customizable toolbar.</p></li>

            <li><p> Provides HTML view to edit the source directly for developers.</p></li>

            <li><p> Supports third - party library integration.</p></li>

            <li><p> Allows preview of modified content before saving it.</p></li>

            <li><p> Handles images, hyperlinks, video, hyperlinks, uploads, etc.</p></li>

            <li><p> Contains undo / redo manager.</p></li>

            <li><p> Creates bulleted and numbered lists.</p></li>

        </ul>";
}

@Html.EJS().RichTextEditor("google-font").FontFamily(e => e.Items((object)ViewBag.fontItems)).ToolbarSettings(e => e.Items((object)ViewBag.tools)).Value(value).Render()
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Great+Vibes">
public class HomeController : Controller
{

    public ActionResult Index()
    {
        object item1 = new
        {
            text = "Segoe UI",
            value = "Segoe UI"
        };
        object item2 = new
        {
            text = "Roboto",
            value = "Roboto"
        };
        object item3 = new
        {
            text = "Great vibes",
            value = "Great Vibes,cursive"
        };
        object item4 = new
        {
            text = "Noto Sans",
            value = "Noto Sans"
        };
        object item5 = new
        {
            text = "Impact",
            value = "Impact,Charcoal,sans-serif"
        };
        object item6 = new
        {
            text = "Tahoma",
            value = "Tahoma,Geneva,sans-serif"
        };
        ViewBag.fontItems = items = new[] { item1, item2, item3, item4, item5, item6 };
        ViewBag.tools = new[] {
        "Bold", "Italic", "Underline", "StrikeThrough",
        "FontName", "FontSize", "FontColor", "BackgroundColor",
        "LowerCase", "UpperCase", "|",
        "Formats", "Alignments", "OrderedList", "UnorderedList",
        "Outdent", "Indent", "|",
        "CreateLink", "Image", "CreateTable", "|", "ClearFormat", "Print",
        "SourceCode", "FullScreen", "|", "Undo", "Redo"
    };
        return View();
    }
}

The below font style links are referred in the page.

<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Great+Vibes">

In the above sample, you can see that we have added two Google web fonts (Roboto and Great vibes) to RichTextEditor.