Build PDFs with Marked Content in C# and .NET

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.

Полный код

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 100-day 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 100-day 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


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.