Generate Marked Content in C# and .NET PDFs

Marked content refers to PDF content which is either adjacent (if Mark Type is Point) or surrounded by (if Mark Type PdfContentMark Element Start and End).

The PdfContentMark element specifies a tag that indicates the role or importance of the marked content and optionally specifies the properties of the marked content.

In the following example, you can learn how to mark geometric content, which is a visual representation of specific Unicode content.

insert a rich text content control

Complete code

using System;
using System.IO;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;
using SautinSoft.Pdf.Content.Marked;
using SautinSoft.Pdf.Objects;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Create PDF marked content.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/marked-content.php
        /// </remarks>
        static void Main(string[] args)
        {
            // Before starting this example, please get a free trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");

            using (var document = new PdfDocument())
            {
                var page = document.Pages.Add();

                // Surround the path with the marked content start and marked content end elements.
                var markStart = page.Content.Elements.AddMarkStart(new PdfContentMarkTag(PdfContentMarkTagRole.Span));

                var markedProperties = markStart.GetEditableProperties().GetDictionary();

                // Add the path that is a visual representation of the letter 'H'.
                var path = page.Content.Elements.AddPath()
                    .BeginSubpath(100, 600).LineTo(100, 800)
                    .BeginSubpath(100, 700).LineTo(200, 700)
                    .BeginSubpath(200, 600).LineTo(200, 800);

                var format = path.Format;
                format.Stroke.IsApplied = true;
                format.Stroke.Width = 10;

                page.Content.Elements.AddMarkEnd();

                document.Save("MarkedContent.pdf");
            }

            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("MarkedContent.pdf") { UseShellExecute = true });
        }
    }
}

Download

Option Infer On

Imports System
Imports System.IO
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content
Imports SautinSoft.Pdf.Content.Marked
Imports SautinSoft.Pdf.Objects

Namespace Sample
	Friend Class Sample
		''' <summary>
		''' Create PDF marked content.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/marked-content.php
		''' </remarks>
		Shared Sub Main(ByVal args() As String)
			' Before starting this example, please get a free trial key:
			' https://sautinsoft.com/start-for-free/

			' Apply the key here:
			' PdfDocument.SetLicense("...");

			Using document = New PdfDocument()
				Dim page = document.Pages.Add()

				' Surround the path with the marked content start and marked content end elements.
				Dim markStart = page.Content.Elements.AddMarkStart(New PdfContentMarkTag(PdfContentMarkTagRole.Span))

				Dim markedProperties = markStart.GetEditableProperties().GetDictionary()

				' Add the path that is a visual representation of the letter 'H'.
				Dim path = page.Content.Elements.AddPath().BeginSubpath(100, 600).LineTo(100, 800).BeginSubpath(100, 700).LineTo(200, 700).BeginSubpath(200, 600).LineTo(200, 800)

				Dim format = path.Format
				format.Stroke.IsApplied = True
				format.Stroke.Width = 10

				page.Content.Elements.AddMarkEnd()

				document.Save("MarkedContent.pdf")
			End Using

			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("MarkedContent.pdf") With {.UseShellExecute = True})
		End Sub
	End Class
End Namespace

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.