Add Marked Content to PDFs with C# and .NET

Marked-up PDF content is content that is either nearby (if the markup type is a dot) or in the environment (if the markup type is an element of the beginning and end of the markup). The PDF markup element defines a tag that indicates the role or importance of the published content and, if necessary, defines the properties of the marked-up content.

Marked-up content is useful for:

  • Improving accessibility: Helps screen readers and other assistive technologies better interpret PDF content.
  • Simplified navigation: Allows users and programs to easily find important parts of the document and navigate to them.
  • Semantic markup: provides additional information about the structure and content of the document.
      1. Add SautinSoft.PDF from NuGet.
      2. Create a new PDF document and add a page.
      3. Create a path that visually represents the letter 'H'.
      4. Apply the format settings for the path (line thickness).
      5. Apply an element of the end of the markup.
      6. Save the document.

      Output result:

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


      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.