Transformation invisible text using C# and .NET

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.