Page Breaks 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.

Page Breaks Example for Blazor Description

This example demonstrates how to programmatically add page breaks inlines to paragraphs.


Page Breaks Example

C# Page Breaks 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.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 - NPageBreaksExample";

			// 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()
		{
			return null;
		}
		/// 
		/// 
		/// 
		/// 
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to programmatically add page breaks inlines to paragraphs.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Rich Text Paragraphs", "https://www.nevron.com/docs/openvision/rich-text-paragraphs.html"), ("Rich Text Inline Elements", "https://www.nevron.com/docs/openvision/rich-text-inline-elements.html"), ("Rich Text Sections", "https://www.nevron.com/docs/openvision/rich-text-sections.html"), ("Rich Text Block Layout", "https://www.nevron.com/docs/openvision/rich-text-block-layout.html"), }; } private void PopulateRichText() { NSection section = new NSection(); m_RichText.Content.Sections.Add(section); m_RichText.Content.Layout = ENTextLayout.Print; /////////////// /* NParagraph par1 = new NParagraph("Paragraph 1"); par1.Inlines.Add(new NPageBreakInline()); section.Blocks.Add(par1); NParagraph par2 = new NParagraph("Paragraph 2"); section.Blocks.Add(par2); /////////////// return;*/ section.Blocks.Add(GetDescriptionBlock("Page Breaks", "The example shows how to add page break inlines.", 1)); // paragraphs with different horizontal alignment section.Blocks.Add(GetTitleParagraph("Paragraphs can contain explicit page breaks", 2)); for (int i = 0; i < 23; i++) { if (i % 10 == 0) { section.Blocks.Add(GetParagraphWithPageBreak()); } else { section.Blocks.Add(GetParagraphWithoutPageBreak()); } } section.Blocks.Add(GetTitleParagraph("Tables can also contain page breaks", 2)); NTable table = new NTable(3, 3); for (int row = 0; row < table.Rows.Count; row++) { for (int col = 0; col < table.Columns.Count; col++) { // by default cells contain a single paragraph table.Rows[row].Cells[col].Blocks.Clear(); table.Rows[row].Cells[col].Blocks.Add(GetParagraphWithoutPageBreak()); } } table.Rows[1].Cells[1].Blocks.Clear(); table.Rows[1].Cells[1].Blocks.Add(GetParagraphWithPageBreak()); section.Blocks.Add(table); } #endregion #region Implementation /// /// Gets a paragraph without an explicit page break /// /// /// private static NParagraph GetParagraphWithoutPageBreak() { string text = string.Empty; for (int i = 0; i < 10; i++) { if (text.Length > 0) { text += " "; } text += "This is a paragraph without an explicit page break."; } return new NParagraph(text); } /// /// Gets a paragraph with an explicit page break /// /// /// private static NParagraph GetParagraphWithPageBreak() { string text = string.Empty; NParagraph paragraph = new NParagraph(); for (int i = 0; i < 5; i++) { if (text.Length > 0) { text += " "; } text += "This is a paragraph with an explicit page break."; } paragraph.Inlines.Add(new NTextInline(text)); NTextInline inline = new NTextInline("Page break appears here!"); inline.FontStyle |= ENFontStyle.Bold; paragraph.Inlines.Add(inline); paragraph.Inlines.Add(new NPageBreakInline()); paragraph.Inlines.Add(new NTextInline(text)); return paragraph; } #endregion #region Event Handlers #endregion #region Fields private NRichTextView m_RichText; #endregion #region Static Methods private static NParagraph GetDescriptionParagraph(string text) { return new NParagraph(text); } private static NParagraph GetTitleParagraphNoBorder(string text, int level) { double fontSize = 10; ENFontStyle fontStyle = ENFontStyle.Regular; switch (level) { case 1: fontSize = 16; fontStyle = ENFontStyle.Bold; break; case 2: fontSize = 10; fontStyle = ENFontStyle.Bold; break; } NParagraph paragraph = new NParagraph(); paragraph.HorizontalAlignment = ENAlign.Left; paragraph.FontSize = fontSize; paragraph.FontStyle = fontStyle; NTextInline textInline = new NTextInline(text); textInline.FontStyle = fontStyle; textInline.FontSize = fontSize; paragraph.Inlines.Add(textInline); return paragraph; } /// /// Gets a paragraph with title formatting /// /// /// private static NParagraph GetTitleParagraph(string text, int level) { NColor color = NColor.Black; NParagraph paragraph = GetTitleParagraphNoBorder(text, level); paragraph.HorizontalAlignment = ENAlign.Left; paragraph.Border = CreateLeftTagBorder(color); paragraph.BorderThickness = defaultBorderThickness; return paragraph; } private static NGroupBlock GetDescriptionBlock(string title, string description, int level) { NColor color = NColor.Black; NParagraph paragraph = GetTitleParagraphNoBorder(title, level); NGroupBlock groupBlock = new NGroupBlock(); groupBlock.ClearMode = ENClearMode.All; groupBlock.Blocks.Add(paragraph); groupBlock.Blocks.Add(GetDescriptionParagraph(description)); groupBlock.Border = CreateLeftTagBorder(color); groupBlock.BorderThickness = defaultBorderThickness; return groupBlock; } /// /// Creates a left tag border with the specified border /// /// /// private static NBorder CreateLeftTagBorder(NColor color) { NBorder border = new NBorder(); border.LeftSide = new NBorderSide(); border.LeftSide.Fill = new NColorFill(color); return border; } #endregion #region Constants private static readonly NMargins defaultBorderThickness = new NMargins(5.0, 0.0, 0.0, 0.0); #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Page Breaks Example for Blazor Solution