HTML Export Example for WPF

Nevron NOV RichTextEditor for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF RichTextEditor examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

HTML Export Example for WPF Description

This example demonstrates the HTML export capabilities of the Nevron Rich Text widget. Simply select one of the preloaded examples from the combo box to the right and see it exported. You can also edit the text document and press the Export button when ready.


Html Export Example

C# HTML Export Example Code for Nevron RichTextEditor for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.IO;
using Nevron.Nov.Layout;
using Nevron.Nov.Text;
using Nevron.Nov.Text.Formats;
using Nevron.Nov.Text.Formats.Html;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NHtmlExportExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

        #region Example

        public NWidget CreateExampleContent()
        {
            NSplitter splitter = new NSplitter();
            splitter.SplitMode = ENSplitterSplitMode.Proportional;
            splitter.SplitFactor = 0.5;

            // Create the rich text view
            NRichTextViewWithRibbon richTextWithRibbon = new NRichTextViewWithRibbon();
            m_RichText = richTextWithRibbon.View;
            m_RichText.AcceptsTab = true;
            m_RichText.Content.Sections.Clear();

            // Stack the rich text with ribbon and an export button
            NButton exportButton = new NButton("Export");
            exportButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center;
            exportButton.Click += OnExportButtonClick;

            splitter.Pane1.Content = CreatePairBox(richTextWithRibbon, exportButton);

            // Create the HTML rich text box
			m_HtmlTextBox = new NTextBox();
			m_HtmlTextBox.AcceptsEnter = true;
			m_HtmlTextBox.AcceptsTab = true;
			m_HtmlTextBox.Multiline = true;
			m_HtmlTextBox.WordWrap = false;
			m_HtmlTextBox.VScrollMode = ENScrollMode.WhenNeeded;
			m_HtmlTextBox.HScrollMode = ENScrollMode.WhenNeeded;
			m_HtmlTextBox.ReadOnly = true;
			splitter.Pane2.Content = new NGroupBox("Exported HTML", m_HtmlTextBox);

            return splitter;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            stack.VerticalSpacing = 10;

			// Create the export settings check boxes
			m_InlineStylesCheckBox = new NCheckBox("Inline styles", false);
			m_InlineStylesCheckBox.CheckedChanged += OnSettingsCheckBoxCheckedChanged;
			stack.Add(m_InlineStylesCheckBox);

			m_MinifyHtmlCheckBox = new NCheckBox("Minify HTML", false);
			m_MinifyHtmlCheckBox.CheckedChanged += OnSettingsCheckBoxCheckedChanged;
			stack.Add(m_MinifyHtmlCheckBox);

            // Create the predefined tests list box
            NListBox testListBox = new NListBox();
            testListBox.Items.Add(CreateTestListBoxItem(new NRichTextBorders()));
            testListBox.Items.Add(CreateTestListBoxItem(new NRichTextLists()));
            testListBox.Items.Add(CreateTestListBoxItem(new NRichTextTables()));
            testListBox.Items.Add(CreateTestListBoxItem(new NRichTextTextStyles()));
			testListBox.Items.Add(CreateTestListBoxItem(new NRichTextElementPositioning()));
            testListBox.Selection.Selected += OnTestListBoxItemSelected;

            // Add the list box in a group box
            stack.Add(new NGroupBox("Predefined text documents", testListBox));

            // Create the Load from file group box
            NDockPanel dockPanel = new NDockPanel();
            dockPanel.HorizontalSpacing = 3;
            dockPanel.VerticalSpacing = 3;

            NButton loadButton = new NButton("Load");
            loadButton.Click += OnLoadButtonClick;
            NDockLayout.SetDockArea(loadButton, ENDockArea.Bottom);
            dockPanel.Add(loadButton);

            m_FileNameTextBox = new NTextBox();
            m_FileNameTextBox.VerticalPlacement = ENVerticalPlacement.Center;
            NDockLayout.SetDockArea(m_FileNameTextBox, ENDockArea.Center);
            dockPanel.Add(m_FileNameTextBox);

            NButton browseButton = new NButton("...");
            browseButton.Click += OnBrowseButtonClick;
            NDockLayout.SetDockArea(browseButton, ENDockArea.Right);
            dockPanel.Add(browseButton);

            stack.Add(new NGroupBox("Load from file", dockPanel));

            m_ElapsedTimeLabel = new NLabel();
            stack.Add(m_ElapsedTimeLabel);

            // Select the initial test
            testListBox.Selection.SingleSelect(testListBox.Items[0]);

            return stack;
        }
		public string GetExampleDescription()
        {
            return @"

This example demonstrates the HTML export capabilities of the Nevron Rich Text widget. Simply select one of the preloaded examples from the combo box to the right and see it exported. You can also edit the text document and press the Export button when ready.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text - Web Page (HTML) Export", "https://www.nevron.com/docs/openvision/rich-text-html-export.html"), ("Rich Text - Saving Documents", "https://www.nevron.com/docs/openvision/rich-text-saving-document.html"), }; } #endregion #region Implementation private void ExportToHtml() { m_ElapsedTimeLabel.Text = null; Stopwatch stopwatch = Stopwatch.StartNew(); using (MemoryStream stream = new MemoryStream()) { // Create and configure HTML save settings NHtmlSaveSettings saveSettings = new NHtmlSaveSettings(); saveSettings.InlineStyles = m_InlineStylesCheckBox.Checked; saveSettings.MinifyHtml = m_MinifyHtmlCheckBox.Checked; // Save to HTML m_RichText.SaveToStreamAsync(stream, NTextFormat.Html, saveSettings); stopwatch.Stop(); LoadHtmlSource(stream); } m_ElapsedTimeLabel.Text = "Export done in: " + stopwatch.ElapsedMilliseconds.ToString() + " ms."; } private void LoadHtmlSource(Stream stream) { stream.Position = 0; byte[] bytes = NStreamHelpers.ReadToEnd(stream); m_HtmlTextBox.Text = NEncoding.UTF8.GetString(bytes); } private bool LoadRtfFromFile(string fileName) { try { m_RichText.LoadFromFileAsync(fileName); } catch { m_ElapsedTimeLabel.Text = "RTF loading failed."; return false; } return true; } #endregion #region Event Handlers private void OnExportButtonClick(NEventArgs arg1) { ExportToHtml(); } private void OnSettingsCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ExportToHtml(); } private void OnTestListBoxItemSelected(NItemEventArgs arg1) { NListBoxItem selectedItem = arg1.Item; if (selectedItem == null) return; NRichTextToHtmlExample example = selectedItem.Tag as NRichTextToHtmlExample; if (example == null) return; // Recreate the content of the Nevron rich text widget NDocumentBlock documentRoot = example.CreateDocument(); NRichTextDocument document = new NRichTextDocument(); document.Content = documentRoot; document.Evaluate(); m_RichText.Document = document; ExportToHtml(); } private void OnBrowseButtonClick(NEventArgs arg1) { NOpenFileDialog openFileDialog = new NOpenFileDialog(); openFileDialog.FileTypes = new NFileDialogFileType[] { new NFileDialogFileType("Word Documents and Rich Text Files", new string[] { "docx", "rtf" }) }; openFileDialog.SelectedFilterIndex = 0; openFileDialog.MultiSelect = false; openFileDialog.InitialDirectory = String.Empty; openFileDialog.Closed += result => { if (result.Result != ENCommonDialogResult.OK) return; string fileName = result.Files[0].Path; m_FileNameTextBox.Text = fileName; if (LoadRtfFromFile(fileName)) { ExportToHtml(); } }; openFileDialog.RequestShow(); } private void OnLoadButtonClick(NEventArgs arg1) { string fileName = m_FileNameTextBox.Text; NFile file = NFileSystem.Current.GetFile(fileName); if (file == null) return; file.Exists().Then(delegate (bool exists) { if(exists && LoadRtfFromFile(fileName)) ExportToHtml(); }); } #endregion #region Fields private NRichTextView m_RichText; private NTextBox m_HtmlTextBox; private NCheckBox m_InlineStylesCheckBox; private NCheckBox m_MinifyHtmlCheckBox; private NTextBox m_FileNameTextBox; private NLabel m_ElapsedTimeLabel; #endregion #region Static Methods private static NListBoxItem CreateTestListBoxItem(NRichTextToHtmlExample example) { NListBoxItem item = new NListBoxItem(example.Title); item.Tag = example; return item; } private static NPairBox CreatePairBox(NWidget widget1, NWidget widget2) { NPairBox pairBox = new NPairBox(widget1, widget2, ENPairBoxRelation.Box1AboveBox2); pairBox.FitMode = ENStackFitMode.First; pairBox.FillMode = ENStackFillMode.First; pairBox.Spacing = NDesign.VerticalSpacing; return pairBox; } #endregion #region Constants #endregion #region Nested Types private abstract class NRichTextToHtmlExample { public NRichTextToHtmlExample(string title) { m_Title = title; } public string Title { get { return m_Title; } } public virtual NDocumentBlock CreateDocument() { NDocumentBlock document = new NDocumentBlock(); document.Information.Title = m_Title; NSection section = new NSection(); document.Sections.Add(section); NParagraph heading = new NParagraph(m_Title); section.Blocks.Add(heading); heading.HorizontalAlignment = ENAlign.Center; heading.FontSize = 24; return document; } private string m_Title; } private class NRichTextBorders : NRichTextToHtmlExample { public NRichTextBorders() : base("Borders") { } public override NDocumentBlock CreateDocument() { NDocumentBlock document = base.CreateDocument(); NSection section = document.Sections[0]; NParagraph p = new NParagraph("Black solid border"); section.Blocks.Add(p); p.Border = NBorder.CreateFilledBorder(NColor.Black); p.BorderThickness = new NMargins(1); p = new NParagraph("Black dashed border"); section.Blocks.Add(p); p.Border = new NBorder(); p.Border.MiddleStroke = new NStroke(5, NColor.Black, ENDashStyle.Dash); p.BorderThickness = new NMargins(5); p = new NParagraph("Green/DarkGreen two-color border"); section.Blocks.Add(p); p.Border = NBorder.CreateTwoColorBorder(NColor.Green, NColor.DarkGreen); p.BorderThickness = new NMargins(10); p = new NParagraph("A border with left, right and bottom sides and wide but not set top side"); section.Blocks.Add(p); p.Border = new NBorder(); p.Border.LeftSide = new NThreeColorsBorderSide(NColor.Black, NColor.Gray, NColor.LightGray); p.Border.RightSide = new NBorderSide(); p.Border.RightSide.OuterStroke = new NStroke(10, NColor.Blue, ENDashStyle.Dot); p.Border.BottomSide = new NBorderSide(NColor.Red); p.BorderThickness = new NMargins(9, 50, 5, 5); return document; } } private class NRichTextTextStyles : NRichTextToHtmlExample { public NRichTextTextStyles() : base("Text Styles") { } public override NDocumentBlock CreateDocument() { NDocumentBlock document = base.CreateDocument(); NSection section = document.Sections[0]; section.Blocks.Add(new NParagraph("This is the first paragraph.")); section.Blocks.Add(new NParagraph("This is the second paragraph.\nThis is part of the second paragraph, too.")); NGroupBlock div = new NGroupBlock(); section.Blocks.Add(div); div.Fill = new NColorFill(NColor.Red); NParagraph p = new NParagraph("This is a paragraph in a div. It should have red underlined text."); div.Blocks.Add(p); p.FontStyle = ENFontStyle.Underline; p = new NParagraph("This is another paragraph in the div. It contains a "); div.Blocks.Add(p); NTextInline inline = new NTextInline("bold italic blue inline"); p.Inlines.Add(inline); inline.Fill = new NColorFill(NColor.Blue); inline.FontStyle = ENFontStyle.Bold | ENFontStyle.Italic; p.Inlines.Add(new NTextInline(".")); return document; } } private class NRichTextTables : NRichTextToHtmlExample { public NRichTextTables() : base("Tables") { } public override NDocumentBlock CreateDocument() { NDocumentBlock document = base.CreateDocument(); // Create a simple 2x2 table NSection section = document.Sections[0]; NTable table = new NTable(2, 2); section.Blocks.Add(table); for (int row = 0, i = 1; row < table.Rows.Count; row++) { for (int col = 0; col < table.Columns.Count; col++, i++) { InitCell(table.Rows[row].Cells[col], "Cell " + i.ToString()); } } // Create a 3x3 table with rowspans and colspans table = new NTable(4, 3); section.Blocks.Add(table); InitCell(table.Rows[0].Cells[0], 2, 1, "Cell 1 (2 rows)"); InitCell(table.Rows[0].Cells[1], "Cell 2"); InitCell(table.Rows[0].Cells[2], "Cell 3"); InitCell(table.Rows[1].Cells[1], 1, 2, "Cell 4 (2 cols)"); InitCell(table.Rows[2].Cells[0], "Cell 5"); InitCell(table.Rows[2].Cells[1], 2, 2, "Cell 6 (2 rows x 2 cols)"); InitCell(table.Rows[3].Cells[0], "Cell 7"); return document; } private static void InitCell(NTableCell cell, string text) { InitCell(cell, 1, 1, text); } private static void InitCell(NTableCell cell, int rowSpan, int colSpan, string text) { if (rowSpan != 1) { cell.RowSpan = rowSpan; } if (colSpan != 1) { cell.ColSpan = colSpan; } // By default cells contain a single paragraph cell.Blocks.Clear(); cell.Blocks.Add(new NParagraph(text)); // Create a border cell.Border = NBorder.CreateFilledBorder(NColor.Black); cell.BorderThickness = new NMargins(1); } } private class NRichTextLists : NRichTextToHtmlExample { public NRichTextLists() : base("Lists") { } public override NDocumentBlock CreateDocument() { NDocumentBlock document = base.CreateDocument(); NSection section = document.Sections[0]; // Add bullet lists of all unordered types ENBulletListTemplateType[] bulletTypes = new ENBulletListTemplateType[] { ENBulletListTemplateType.Bullet }; for (int i = 0; i < bulletTypes.Length; i++) { NBulletList bulletList = new NBulletList(ENBulletListTemplateType.Bullet); document.BulletLists.Add(bulletList); for (int j = 1; j <= 3; j++) { NParagraph paragraph = new NParagraph("This is parargaph number " + j.ToString() + ". This paragraph is contained in a bullet list of type " + bulletTypes[i].ToString()); paragraph.SetBulletList(bulletList, 0); section.Blocks.Add(paragraph); } } // Add bullet lists of all ordered types bulletTypes = new ENBulletListTemplateType[] { ENBulletListTemplateType.Decimal, ENBulletListTemplateType.LowerAlpha, ENBulletListTemplateType.LowerRoman, ENBulletListTemplateType.UpperAlpha, ENBulletListTemplateType.UpperRoman }; for (int i = 0; i < bulletTypes.Length; i++) { section.Blocks.Add(new NParagraph()); NBulletList bulletList = new NBulletList(bulletTypes[i]); for (int j = 1; j <= 3; j++) { NParagraph paragraph = new NParagraph("Bullet List Item " + j.ToString(), bulletList, 0); section.Blocks.Add(paragraph); for (int z = 1; z <= 3; z++) { NParagraph par2 = new NParagraph("Bullet List Sub Item " + z.ToString(), bulletList, 1); section.Blocks.Add(par2); } } } return document; } } private class NRichTextElementPositioning : NRichTextToHtmlExample { public NRichTextElementPositioning() : base("Element Positioning") { } public override NDocumentBlock CreateDocument() { NDocumentBlock document = base.CreateDocument(); NSection section = document.Sections[0]; NParagraph p = new NParagraph("This is a red paragraph on the left."); p.HorizontalAnchor = ENHorizontalAnchor.Ancestor; p.HorizontalBlockAlignment = ENHorizontalBlockAlignment.Left; p.VerticalAnchor = ENVerticalAnchor.Ancestor; p.XOffset = 20; p.YOffset = 200; p.PreferredWidth = NMultiLength.NewPercentage(25); p.BackgroundFill = new NColorFill(NColor.Red); section.Blocks.Add(p); p = new NParagraph("This is a green paragraph on the top."); p.HorizontalAnchor = ENHorizontalAnchor.Ancestor; p.VerticalAnchor = ENVerticalAnchor.Ancestor; p.VerticalBlockAlignment = ENVerticalBlockAlignment.Top; p.XOffset = 120; p.YOffset = 100; p.PreferredWidth = NMultiLength.NewPercentage(50); p.BackgroundFill = new NColorFill(NColor.Green); section.Blocks.Add(p); p = new NParagraph("This is a blue paragraph on the right."); p.HorizontalAnchor = ENHorizontalAnchor.Ancestor; p.HorizontalBlockAlignment = ENHorizontalBlockAlignment.Right; p.VerticalAnchor = ENVerticalAnchor.Ancestor; p.XOffset = 20; p.YOffset = 200; p.PreferredWidth = NMultiLength.NewPercentage(25); p.BackgroundFill = new NColorFill(NColor.Blue); p.Fill = new NColorFill(NColor.White); section.Blocks.Add(p); return document; } } #endregion } }

Download a fully functional C# (.cs) HTML Export Example for WPF Solution

VB.NET HTML Export Example Code for Nevron RichTextEditor for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.IO
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Text
Imports Nevron.Nov.Text.Formats
Imports Nevron.Nov.Text.Formats.Html
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System.Diagnostics
Imports System.IO

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NHtmlExportExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
		pairBox.FillMode = ENStackFillMode.First
		pairBox.FitMode = ENStackFitMode.First
		pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

		' Host the example in the form
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            Dim splitter As NSplitter = New NSplitter()
            splitter.SplitMode = ENSplitterSplitMode.Proportional
            splitter.SplitFactor = 0.5

            ' Create the rich text view
            Dim richTextWithRibbon As NRichTextViewWithRibbon = New NRichTextViewWithRibbon()
            m_RichText = richTextWithRibbon.View
            m_RichText.AcceptsTab = True
            m_RichText.Content.Sections.Clear()

            ' Stack the rich text with ribbon and an export button
            Dim exportButton As NButton = New NButton("Export")
            exportButton.Content.HorizontalPlacement = ENHorizontalPlacement.Center
            exportButton.Click += AddressOf OnExportButtonClick

            splitter.Pane1.Content = CreatePairBox(richTextWithRibbon, exportButton)

            ' Create the HTML rich text box
            m_HtmlTextBox = New NTextBox()
            m_HtmlTextBox.AcceptsEnter = True
            m_HtmlTextBox.AcceptsTab = True
            m_HtmlTextBox.Multiline = True
            m_HtmlTextBox.WordWrap = False
            m_HtmlTextBox.VScrollMode = ENScrollMode.WhenNeeded
            m_HtmlTextBox.HScrollMode = ENScrollMode.WhenNeeded
            m_HtmlTextBox.ReadOnly = True
            splitter.Pane2.Content = New NGroupBox("Exported HTML", m_HtmlTextBox)

            Return splitter
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            stack.VerticalSpacing = 10

            ' Create the export settings check boxes
            m_InlineStylesCheckBox = New NCheckBox("Inline styles", False)
            Me.m_InlineStylesCheckBox.CheckedChanged += AddressOf OnSettingsCheckBoxCheckedChanged
            stack.Add(m_InlineStylesCheckBox)

            m_MinifyHtmlCheckBox = New NCheckBox("Minify HTML", False)
            Me.m_MinifyHtmlCheckBox.CheckedChanged += AddressOf OnSettingsCheckBoxCheckedChanged
            stack.Add(m_MinifyHtmlCheckBox)

            ' Create the predefined tests list box
            Dim testListBox As NListBox = New NListBox()
            testListBox.Items.Add(CreateTestListBoxItem(New NRichTextBorders()))
            testListBox.Items.Add(CreateTestListBoxItem(New NRichTextLists()))
            testListBox.Items.Add(CreateTestListBoxItem(New NRichTextTables()))
            testListBox.Items.Add(CreateTestListBoxItem(New NRichTextTextStyles()))
            testListBox.Items.Add(CreateTestListBoxItem(New NRichTextElementPositioning()))
            testListBox.Selection.Selected += AddressOf OnTestListBoxItemSelected

            ' Add the list box in a group box
            stack.Add(New NGroupBox("Predefined text documents", testListBox))

            ' Create the Load from file group box
            Dim dockPanel As NDockPanel = New NDockPanel()
            dockPanel.HorizontalSpacing = 3
            dockPanel.VerticalSpacing = 3

            Dim loadButton As NButton = New NButton("Load")
            loadButton.Click += AddressOf OnLoadButtonClick
            NDockLayout.SetDockArea(loadButton, ENDockArea.Bottom)
            dockPanel.Add(loadButton)

            m_FileNameTextBox = New NTextBox()
            m_FileNameTextBox.VerticalPlacement = ENVerticalPlacement.Center
            NDockLayout.SetDockArea(m_FileNameTextBox, ENDockArea.Center)
            dockPanel.Add(m_FileNameTextBox)

            Dim browseButton As NButton = New NButton("...")
            browseButton.Click += AddressOf OnBrowseButtonClick
            NDockLayout.SetDockArea(browseButton, ENDockArea.Right)
            dockPanel.Add(browseButton)

            stack.Add(New NGroupBox("Load from file", dockPanel))

            m_ElapsedTimeLabel = New NLabel()
            stack.Add(m_ElapsedTimeLabel)

            ' Select the initial test
            testListBox.Selection.SingleSelect(testListBox.Items(0))

            Return stack
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates the HTML export capabilities of the Nevron Rich Text widget. Simply select one of the preloaded examples from the combo box to the right and see it exported. You can also edit the text document and press the Export button when ready.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Rich Text - Web Page (HTML) Export", "https://www.nevron.com/docs/openvision/rich-text-html-export.html"), ("Rich Text - Saving Documents", "https://www.nevron.com/docs/openvision/rich-text-saving-document.html")} End Function #End Region #Region "Implementation" Private Sub ExportToHtml() m_ElapsedTimeLabel.Text = Nothing Dim stopwatch As Stopwatch = Stopwatch.StartNew() Using stream As MemoryStream = New MemoryStream() ' Create and configure HTML save settings Dim saveSettings As NHtmlSaveSettings = New NHtmlSaveSettings() saveSettings.InlineStyles = m_InlineStylesCheckBox.Checked saveSettings.MinifyHtml = m_MinifyHtmlCheckBox.Checked ' Save to HTML m_RichText.SaveToStreamAsync(stream, NTextFormat.Html, saveSettings) stopwatch.Stop() LoadHtmlSource(stream) End Using m_ElapsedTimeLabel.Text = "Export done in: " & stopwatch.ElapsedMilliseconds.ToString() & " ms." End Sub Private Sub LoadHtmlSource(stream As Stream) stream.Position = 0 Dim bytes = NStreamHelpers.ReadToEnd(stream) m_HtmlTextBox.Text = NEncoding.UTF8.GetString(bytes) End Sub Private Function LoadRtfFromFile(fileName As String) As Boolean Try m_RichText.LoadFromFileAsync(fileName) Catch m_ElapsedTimeLabel.Text = "RTF loading failed." Return False End Try Return True End Function #End Region #Region "Event Handlers" Private Sub OnExportButtonClick(arg1 As NEventArgs) ExportToHtml() End Sub Private Sub OnSettingsCheckBoxCheckedChanged(arg As NValueChangeEventArgs) ExportToHtml() End Sub Private Sub OnTestListBoxItemSelected(arg1 As NItemEventArgs(Of NListBoxItem)) Dim selectedItem = arg1.Item If selectedItem Is Nothing Then Return Dim example As NRichTextToHtmlExample = TryCast(selectedItem.Tag, NRichTextToHtmlExample) If example Is Nothing Then Return ' Recreate the content of the Nevron rich text widget Dim documentRoot As NDocumentBlock = example.CreateDocument() Dim document As NRichTextDocument = New NRichTextDocument() document.Content = documentRoot document.Evaluate() m_RichText.Document = document ExportToHtml() End Sub Private Sub OnBrowseButtonClick(arg1 As NEventArgs) Dim openFileDialog As NOpenFileDialog = New NOpenFileDialog() openFileDialog.FileTypes = New NFileDialogFileType() {New NFileDialogFileType("Word Documents and Rich Text Files", New String() {"docx", "rtf"})} openFileDialog.SelectedFilterIndex = 0 openFileDialog.MultiSelect = False openFileDialog.InitialDirectory = String.Empty openFileDialog.Closed += Sub(result) If result.Result IsNot ENCommonDialogResult.OK Then Return Dim fileName As String = result.Files(0).Path m_FileNameTextBox.Text = fileName If LoadRtfFromFile(fileName) Then ExportToHtml() End If End Sub openFileDialog.RequestShow() End Sub Private Sub OnLoadButtonClick(arg1 As NEventArgs) Dim fileName = m_FileNameTextBox.Text Dim file = NFileSystem.Current.GetFile(fileName) If file Is Nothing Then Return file.Exists().[Then](Sub(exists As Boolean) If exists AndAlso LoadRtfFromFile(fileName) Then ExportToHtml() End Sub) End Sub #End Region #Region "Fields" Private m_RichText As NRichTextView Private m_HtmlTextBox As NTextBox Private m_InlineStylesCheckBox As NCheckBox Private m_MinifyHtmlCheckBox As NCheckBox Private m_FileNameTextBox As NTextBox Private m_ElapsedTimeLabel As NLabel #End Region #Region "Static Methods" Private Shared Function CreateTestListBoxItem(example As NRichTextToHtmlExample) As NListBoxItem Dim item As NListBoxItem = New NListBoxItem(example.Title) item.Tag = example Return item End Function Private Shared Function CreatePairBox(widget1 As NWidget, widget2 As NWidget) As NPairBox Dim pairBox As NPairBox = New NPairBox(widget1, widget2, ENPairBoxRelation.Box1AboveBox2) pairBox.FitMode = ENStackFitMode.First pairBox.FillMode = ENStackFillMode.First pairBox.Spacing = NDesign.VerticalSpacing Return pairBox End Function #End Region #Region "Constants" #End Region #Region "Nested Types" Private MustInherit Class NRichTextToHtmlExample Public Sub New(title As String) m_Title = title End Sub Public ReadOnly Property Title As String Get Return m_Title End Get End Property Public Overridable Function CreateDocument() As NDocumentBlock Dim document As NDocumentBlock = New NDocumentBlock() document.Information.Title = m_Title Dim section As NSection = New NSection() document.Sections.Add(section) Dim heading As NParagraph = New NParagraph(m_Title) section.Blocks.Add(heading) heading.HorizontalAlignment = ENAlign.Center heading.FontSize = 24 Return document End Function Private m_Title As String End Class Private Class NRichTextBorders Inherits NRichTextToHtmlExample Public Sub New() MyBase.New("Borders") End Sub Public Overrides Function CreateDocument() As NDocumentBlock Dim document As NDocumentBlock = MyBase.CreateDocument() Dim section = document.Sections(0) Dim p As NParagraph = New NParagraph("Black solid border") section.Blocks.Add(p) p.Border = NBorder.CreateFilledBorder(NColor.Black) p.BorderThickness = New NMargins(1) p = New NParagraph("Black dashed border") section.Blocks.Add(p) p.Border = New NBorder() p.Border.MiddleStroke = New NStroke(5, NColor.Black, ENDashStyle.Dash) p.BorderThickness = New NMargins(5) p = New NParagraph("Green/DarkGreen two-color border") section.Blocks.Add(p) p.Border = NBorder.CreateTwoColorBorder(NColor.Green, NColor.DarkGreen) p.BorderThickness = New NMargins(10) p = New NParagraph("A border with left, right and bottom sides and wide but not set top side") section.Blocks.Add(p) p.Border = New NBorder() p.Border.LeftSide = New NThreeColorsBorderSide(NColor.Black, NColor.Gray, NColor.LightGray) p.Border.RightSide = New NBorderSide() p.Border.RightSide.OuterStroke = New NStroke(10, NColor.Blue, ENDashStyle.Dot) p.Border.BottomSide = New NBorderSide(NColor.Red) p.BorderThickness = New NMargins(9, 50, 5, 5) Return document End Function End Class Private Class NRichTextTextStyles Inherits NRichTextToHtmlExample Public Sub New() MyBase.New("Text Styles") End Sub Public Overrides Function CreateDocument() As NDocumentBlock Dim document As NDocumentBlock = MyBase.CreateDocument() Dim section = document.Sections(0) section.Blocks.Add(New NParagraph("This is the first paragraph.")) section.Blocks.Add(New NParagraph("This is the second paragraph." & vbLf & "This is part of the second paragraph, too.")) Dim div As NGroupBlock = New NGroupBlock() section.Blocks.Add(div) div.Fill = New NColorFill(NColor.Red) Dim p As NParagraph = New NParagraph("This is a paragraph in a div. It should have red underlined text.") div.Blocks.Add(p) p.FontStyle = ENFontStyle.Underline p = New NParagraph("This is another paragraph in the div. It contains a ") div.Blocks.Add(p) Dim inline As NTextInline = New NTextInline("bold italic blue inline") p.Inlines.Add(inline) inline.Fill = New NColorFill(NColor.Blue) inline.FontStyle = ENFontStyle.Bold Or ENFontStyle.Italic p.Inlines.Add(New NTextInline(".")) Return document End Function End Class Private Class NRichTextTables Inherits NRichTextToHtmlExample Public Sub New() MyBase.New("Tables") End Sub Public Overrides Function CreateDocument() As NDocumentBlock Dim document As NDocumentBlock = MyBase.CreateDocument() ' Create a simple 2x2 table Dim section = document.Sections(0) Dim table As NTable = New NTable(2, 2) section.Blocks.Add(table) Dim row = 0, i = 1 While row < table.Rows.Count Dim col = 0 While col < table.Columns.Count Call InitCell(table.Rows(row).Cells(col), "Cell " & i.ToString()) col += 1 i += 1 End While row += 1 End While ' Create a 3x3 table with rowspans and colspans table = New NTable(4, 3) section.Blocks.Add(table) InitCell(table.Rows(0).Cells(0), 2, 1, "Cell 1 (2 rows)") InitCell(table.Rows(0).Cells(1), "Cell 2") InitCell(table.Rows(0).Cells(2), "Cell 3") InitCell(table.Rows(1).Cells(1), 1, 2, "Cell 4 (2 cols)") InitCell(table.Rows(2).Cells(0), "Cell 5") InitCell(table.Rows(2).Cells(1), 2, 2, "Cell 6 (2 rows x 2 cols)") InitCell(table.Rows(3).Cells(0), "Cell 7") Return document End Function Private Shared Sub InitCell(cell As NTableCell, text As String) InitCell(cell, 1, 1, text) End Sub Private Shared Sub InitCell(cell As NTableCell, rowSpan As Integer, colSpan As Integer, text As String) If rowSpan <> 1 Then cell.RowSpan = rowSpan End If If colSpan <> 1 Then cell.ColSpan = colSpan End If ' By default cells contain a single paragraph cell.Blocks.Clear() cell.Blocks.Add(New NParagraph(text)) ' Create a border cell.Border = NBorder.CreateFilledBorder(NColor.Black) cell.BorderThickness = New NMargins(1) End Sub End Class Private Class NRichTextLists Inherits NRichTextToHtmlExample Public Sub New() MyBase.New("Lists") End Sub Public Overrides Function CreateDocument() As NDocumentBlock Dim document As NDocumentBlock = MyBase.CreateDocument() Dim section = document.Sections(0) ' Add bullet lists of all unordered types Dim bulletTypes = New ENBulletListTemplateType() {ENBulletListTemplateType.Bullet} For i = 0 To bulletTypes.Length - 1 Dim bulletList As NBulletList = New NBulletList(ENBulletListTemplateType.Bullet) document.BulletLists.Add(bulletList) For j = 1 To 3 Dim paragraph As NParagraph = New NParagraph("This is parargaph number " & j.ToString() & ". This paragraph is contained in a bullet list of type " & bulletTypes(i).ToString()) paragraph.SetBulletList(bulletList, 0) section.Blocks.Add(paragraph) Next Next ' Add bullet lists of all ordered types bulletTypes = New ENBulletListTemplateType() {ENBulletListTemplateType.Decimal, ENBulletListTemplateType.LowerAlpha, ENBulletListTemplateType.LowerRoman, ENBulletListTemplateType.UpperAlpha, ENBulletListTemplateType.UpperRoman} For i = 0 To bulletTypes.Length - 1 section.Blocks.Add(New NParagraph()) Dim bulletList As NBulletList = New NBulletList(bulletTypes(i)) For j = 1 To 3 Dim paragraph As NParagraph = New NParagraph("Bullet List Item " & j.ToString(), bulletList, 0) section.Blocks.Add(paragraph) For z = 1 To 3 Dim par2 As NParagraph = New NParagraph("Bullet List Sub Item " & z.ToString(), bulletList, 1) section.Blocks.Add(par2) Next Next Next Return document End Function End Class Private Class NRichTextElementPositioning Inherits NRichTextToHtmlExample Public Sub New() MyBase.New("Element Positioning") End Sub Public Overrides Function CreateDocument() As NDocumentBlock Dim document As NDocumentBlock = MyBase.CreateDocument() Dim section = document.Sections(0) Dim p As NParagraph = New NParagraph("This is a red paragraph on the left.") p.HorizontalAnchor = ENHorizontalAnchor.Ancestor p.HorizontalBlockAlignment = ENHorizontalBlockAlignment.Left p.VerticalAnchor = ENVerticalAnchor.Ancestor p.XOffset = 20 p.YOffset = 200 p.PreferredWidth = NMultiLength.NewPercentage(25) p.BackgroundFill = New NColorFill(NColor.Red) section.Blocks.Add(p) p = New NParagraph("This is a green paragraph on the top.") p.HorizontalAnchor = ENHorizontalAnchor.Ancestor p.VerticalAnchor = ENVerticalAnchor.Ancestor p.VerticalBlockAlignment = ENVerticalBlockAlignment.Top p.XOffset = 120 p.YOffset = 100 p.PreferredWidth = NMultiLength.NewPercentage(50) p.BackgroundFill = New NColorFill(NColor.Green) section.Blocks.Add(p) p = New NParagraph("This is a blue paragraph on the right.") p.HorizontalAnchor = ENHorizontalAnchor.Ancestor p.HorizontalBlockAlignment = ENHorizontalBlockAlignment.Right p.VerticalAnchor = ENVerticalAnchor.Ancestor p.XOffset = 20 p.YOffset = 200 p.PreferredWidth = NMultiLength.NewPercentage(25) p.BackgroundFill = New NColorFill(NColor.Blue) p.Fill = New NColorFill(NColor.White) section.Blocks.Add(p) Return document End Function End Class #End Region End Class

Download a fully functional VB.NET (.vb) HTML Export Example for WPF Solution