Manipulation with Content, Element and ElementCollection

Complete code

using System.IO;
using System.Linq;
using SautinSoft.Document;

namespace Example
    class Program
        static void Main(string[] args)
            // Get your free 30-day key here:   

        /// <summary>
        /// Replace all Run elements with Bold formatting to Italic and mark them by yellow.
        /// </summary>
        /// <remarks>
        /// Details:
        /// </remarks>
        static void Manipulation()
            string filePath = @"..\..\..\example.docx";
            DocumentCore dc = DocumentCore.Load(filePath);
            string filePathResult = @"Result-file.pdf";

            foreach (Run run in dc.GetChildElements(true, ElementType.Run))
                if (run.CharacterFormat.Bold == true)
                    run.CharacterFormat.Bold = false;
                    run.CharacterFormat.Italic = true;
                    run.CharacterFormat.BackgroundColor = Color.Yellow;
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePathResult) { UseShellExecute = true });


Imports System.IO
Imports System.Linq
Imports SautinSoft.Document

Module Sample
    Sub Main()
    End Sub
    ''' Get your free 30-day key here:   
    ''' <summary>
    ''' Replace all Run elements with Bold formatting to Italic and mark them by yellow.
    ''' </summary>
    ''' <remarks>
    ''' Details:
    ''' </remarks>
    Sub Manipulation()
        Dim filePath As String = "..\..\..\example.docx"
        Dim dc As DocumentCore = DocumentCore.Load(filePath)
        Dim filePathResult As String = "Result-file.pdf"

        For Each run As Run In dc.GetChildElements(True, ElementType.Run)
            If run.CharacterFormat.Bold = True Then
                run.CharacterFormat.Bold = False
                run.CharacterFormat.Italic = True
                run.CharacterFormat.BackgroundColor = Color.Yellow
            End If
        Next run
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePathResult) With {.UseShellExecute = True})
    End Sub
End Module


If you need a new code example or have a question: email us at 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.