Transformation invisible text using C# and .NET

In the modern world of software development, text and document processing plays a key role. One of the difficult tasks is to work with invisible or hidden text in documents, transform, extract and manage it. In this article, we will take a closer look at how to convert invisible text to C# and .NET using the powerful SautinSoft Document .NET library. You will learn about the advantages of this approach, practical application, as well as the prevalence of such solutions.

Before delving into the technical details, it's worth understanding the concept. Invisible text is a fragment of a document that is hidden or invisible to the user, which is often used for the following purposes: Tags and Comments, Formatting and Structure, Information protection.

What is the use of invisible text for:

  • Automatic document cleaning: removing hidden elements before publishing.
  • Security: detection and protection of hidden content.
  • Format conversion: when translating documents from one format to another, hidden information may be distorted or disappear — automation allows you to control this process.
  • Editing and revision: Displaying hidden comments or labels for verification.

The use of methods of working with invisible text and its transformation in automated systems is quite common in the following areas:

  • Corporate document management solutions: automated verification and preparation of documents.
  • Legal activity: cleaning of documents from hidden data before sending.
  • Media and publishing: automatic processing of large amounts of content.
  • Educational platforms: preparation of educational materials with hidden hints.

Step-by-step guide:

Complete code

using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free trial key here:   
            // https://sautinsoft.com/start-for-free/

            TransformationInvisibleText();     
        }
        /// <summary>
        /// Transformation Invisible Text (PDF to PDF/DOCX, DOCX to PDF/DOCX).
        /// </summary>
		/// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/transformation_invisible_text.php
        /// </remarks>
        static void TransformationInvisibleText()
        {
            string loadPath = @"..\..\..\invisible_text.pdf";
            string savePathPDF = @"..\..\..\visible_text.pdf";
            string savePathDocx = @"..\..\..\visible_text.docx";

            //DocumentCore.Serial = "put your serial here";
            DocumentCore pdf = DocumentCore.Load(loadPath, new PdfLoadOptions()
            {
                 PreserveImages = false,
                 ShowInvisibleText = true,
                 PreserveEmbeddedFonts = true
            });

            CharacterFormat singleCharFormat = new CharacterFormat()
            {            
                FontColor = Color.Black
            };

            pdf.DefaultCharacterFormat = singleCharFormat.Clone();

            foreach (Element element in pdf.GetChildElements(true, ElementType.Run, ElementType.Paragraph))
            {
                if (element is Run)
                   (element as Run).CharacterFormat = singleCharFormat.Clone();
                else if (element is Paragraph)
                    (element as Paragraph).CharacterFormatForParagraphMark = singleCharFormat.Clone();
            }
            pdf.Save(savePathPDF);
            pdf.Save(savePathDocx);
        }
        }
    }

Download

Imports System.IO
Imports SautinSoft.Document

Namespace Example
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			' Get your free trial key here:   
			' https://sautinsoft.com/start-for-free/

			TransformationInvisibleText()
		End Sub
		''' <summary>
		''' Transformation Invisible Text (PDF to PDF/DOCX, DOCX to PDF/DOCX).
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/transformation_invisible_text.php
		''' </remarks>
		Private Shared Sub TransformationInvisibleText()
			Dim loadPath As String = "..\..\..\invisible_text.pdf"
			Dim savePathPDF As String = "..\..\..\visible_text.pdf"
			Dim savePathDocx As String = "..\..\..\visible_text.docx"

			'DocumentCore.Serial = "put your serial here";
			Dim pdf As DocumentCore = DocumentCore.Load(loadPath, New PdfLoadOptions() With {
				.PreserveImages = False,
				.ShowInvisibleText = True,
				.PreserveEmbeddedFonts = True
			})

			Dim singleCharFormat As New CharacterFormat() With {.FontColor = Color.Black}

			pdf.DefaultCharacterFormat = singleCharFormat.Clone()

			For Each element As Element In pdf.GetChildElements(True, ElementType.Run, ElementType.Paragraph)
				If TypeOf element Is Run Then
				   TryCast(element, Run).CharacterFormat = singleCharFormat.Clone()
				ElseIf TypeOf element Is Paragraph Then
					TryCast(element, Paragraph).CharacterFormatForParagraphMark = singleCharFormat.Clone()
				End If
			Next element
			pdf.Save(savePathPDF)
			pdf.Save(savePathDocx)
		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:


Captcha

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.