Nevron Open Vision Documentation
Rich Text Editor / Loading and Saving Documents / Web Pages (HTML)
In This Topic
    Web Pages (HTML)
    In This Topic

    NOV Rich Text view lets you easily import and export documents from and to HTML. You can even load a web page directly in the NOV rich text view, i.e. the NOV text component can act as a mini web browser that includes support for many HTML 5 and CSS 3 features.

     Loading from HTML

    To import an HTML document from a file, you can use the Load methods as shown in the Loading Documents topic. If you want to load a page directly from an URL, you can use the LoadFromUri method:

    Load a web page from an URL
    Copy Code
    richTextView.LoadFromUri(new NUri(""));

    If you want to be notified when the web page has loaded, you should subscribe to the DocumentLoaded event.

    You can also load an HTML document from a string if you convert that string to a byte array first and place it in a memory stream as the following code snippet demonstrates:

    Load HTML from string
    Copy Code
    string html = "<p>This is a paragraph with <b>some bold text</b> and <span style='color:red'>some red text</span>.</p>";
    using (MemoryStream stream = new MemoryStream(NEncoding.UTF8.GetBytes(html)))
        richTextView.LoadFromStream(stream, new NHtmlTextFormat());
     Saving to HTML

    To export a document to HTML, you can use the Save methods as shown in the Saving Documents topic.

    Save to HTML
    Copy Code

    You can pass an NHtmlSaveSettings instance to the Save method if you want to configure the HTML export process. The NHtmlSaveSettings class exposes the following properties:

    • DocumentType - specifies the document type of the generated HTML document. By default set to HTML 5 doc type.
    • EmbedImages - specifies whether to embed images as Base64 strings in the generated HTML documents or not. By default set to true. If this property is set to false, images will be generated in the same folder as the generated HTML files. Note that for some platforms like Silverlight this is not possible due to security reasons.
    • InlineStyles - determines whether to inline the CSS styles in "style" attributes or to create and use CSS classes. By default set to false, which means that the HTML exporter will create and use CSS classes. By default set to false.
    • MinifyHtml - determines whether to minify the resulting HTML by not adding any new lines or tabulations, i.e. whether to place all HTML and CSS code on a single line. By default set to true.

    The following code snippet demonstrates how to save an HTML document to a file with all CSS styles inlined to style attributes:

    Save to HTML with inlined CSS styles
    Copy Code
    NHtmlSaveSettings saveSettings = new NHtmlSaveSettings();
    saveSettings.InlineStyles = true;
    richTextView.SaveToFile(@"C:\HtmlDocument.html", new NHtmlTextFormat(), saveSettings);
    See Also