EPUB Export Example for Blazor

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

EPUB Export Example for Blazor Description

This example demonstrates how to import Electronic Publications (EPUB files) in Nevron Rich Text Editor.


Epub Export Example

C# EPUB Export Example Code for Nevron RichTextEditor for Blazor
Language: C#

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

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

		public Form1()
		{
			InitializeComponent();

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

			// 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()
		{
			// Create the rich text
			NRichTextViewWithRibbon richTextWithRibbon = new NRichTextViewWithRibbon();
			m_RichText = richTextWithRibbon.View;
			m_RichText.AcceptsTab = true;
			m_RichText.Content.Sections.Clear();

			// Populate the rich text
			PopulateRichText();

			return richTextWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();

			NButton exportToEpubButton = new NButton("Export to EPUB...");
			exportToEpubButton.Click += OnExportToEpubButtonClick;
			stack.Add(exportToEpubButton);

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

This example demonstrates how to import Electronic Publications (EPUB files) in Nevron Rich Text Editor.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text - Electronic Publication (EPUB) Export", "https://www.nevron.com/docs/openvision/rich-text-epub-export.html"), ("Rich Text - Saving Documents", "https://www.nevron.com/docs/openvision/rich-text-saving-document.html"), }; } private void PopulateRichText() { NDocumentBlock documentBlock = m_RichText.Content; NRichTextStyle heading1Style = documentBlock.Styles.FindStyleByTypeAndId( ENRichTextStyleType.Paragraph, "Heading1"); // Add chapter 1 NSection section = new NSection(); documentBlock.Sections.Add(section); NParagraph paragraph = new NParagraph("Chapter 1: EPUB Import"); section.Blocks.Add(paragraph); heading1Style.Apply(paragraph); paragraph = new NParagraph("NOV Rich Text Editor lets you import Electronic Publications. " + "Thus you can use it to read e-books on your PC or MAC."); section.Blocks.Add(paragraph); paragraph = new NParagraph("You can also use it to import and edit existing Electronic Publications and books."); section.Blocks.Add(paragraph); // Add chapter 2 section = new NSection(); section.BreakType = ENSectionBreakType.NextPage; documentBlock.Sections.Add(section); paragraph = new NParagraph("Chapter 2: EPUB Export"); section.Blocks.Add(paragraph); heading1Style.Apply(paragraph); paragraph = new NParagraph("NOV Rich Text Editor lets you export a rich text document to an Electronic Publication. " + "Thus you can use it to create e-books on your PC or MAC."); section.Blocks.Add(paragraph); paragraph = new NParagraph("You can also use it to import and edit existing Electronic Publications and books."); section.Blocks.Add(paragraph); } #endregion #region Implementation #endregion #region Event Handlers private void OnExportToEpubButtonClick(NEventArgs arg) { // Create and show a save file dialog NSaveFileDialog saveDialog = new NSaveFileDialog(); saveDialog.Title = "Export to EPUB"; saveDialog.DefaultFileName = "MyBook.epub"; saveDialog.FileTypes = new NFileDialogFileType[] { new NFileDialogFileType(NTextFormat.Epub) }; saveDialog.Closed += OnSaveDialogClosed; saveDialog.RequestShow(); } private void OnSaveDialogClosed(NSaveFileDialogResult arg) { if (arg.Result == ENCommonDialogResult.OK) { m_RichText.SaveToFileAsync(arg.File); } } #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) EPUB Export Example for Blazor Solution