VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging.Pdf Namespace / PdfTextEncodingObfuscator Class / Obfuscate Methods / Obfuscate(PdfDocument,IActionProgressController) Method
Syntax Exceptions Remarks Example Requirements SeeAlso
In This Topic
Obfuscate(PdfDocument,IActionProgressController) Method (PdfTextEncodingObfuscator)
In This Topic
Obfuscates encodings of all fonts containing within the specified PDF document.
Syntax
Exceptions
ExceptionDescription
Thrown if document is null.
Thrown if document contains external fonts.
Thrown if document contains fonts that are not supported for obfuscating.
Remarks

Currently this method does not support obfuscation of Type3 fonts that use other fonts as resources or that are used as resources.

Example

Here is an example that shows how to obfuscate the encoding of embedded fonts in PDF document and output the detailed progress information to the console:


''' <summary>
''' Stores current action description of level 1.
''' </summary>
Shared _currentActionDescriptionLevel1 As String = Nothing

''' <summary>
''' Stores current action description of level 2.
''' </summary>
Shared _currentActionDescriptionLevel2 As String = Nothing

''' <summary>
''' Stores current action description of level 3.
''' </summary>
Shared _currentActionDescriptionLevel3 As String = Nothing

''' <summary>
''' Obfuscates encoding of all fonts of PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
''' <param name="resultFilename">The filename of resulting PDF document.</param>
Public Shared Sub ObfuscateEncodingOfAllFontsWithDetailedInfo(pdfFilename As String, resultFilename As String)
    Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
        ' create obfuscator
        Dim textEncodingObfuscator As New Vintasoft.Imaging.Pdf.PdfTextEncodingObfuscator()
        Try
            ' create progress handler which handles 3 levels of progress
            Dim actionProgressHandler As Vintasoft.Imaging.Utils.IActionProgressHandler = Vintasoft.Imaging.Utils.ActionProgressHandlers.CreateActionProgressHandler(AddressOf OnObfuscateProgressLevel1, AddressOf OnObfuscateProgressLevel2, AddressOf OnObfuscateProgressLevel3)
            ' create progress controller
            Dim progressController As New Vintasoft.Imaging.Utils.ActionProgressController(actionProgressHandler)
            ' obfuscate all fonts
            textEncodingObfuscator.Obfuscate(document, progressController)
            ' pack and save document to new location
            document.Pack(resultFilename)
        Catch ex As System.Exception
            System.Console.WriteLine(ex.Message)
        End Try
    End Using
End Sub

''' <summary>
''' Outputs description of level 1 actions of font obfuscation.
''' </summary>
Private Shared Sub OnObfuscateProgressLevel1(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
    Dim actionDescription As String = e.Description
    ' if action is finished
    If e.Progress = 100 Then
        ' output action description with small indent
        System.Console.WriteLine("  Finished ({0}).", actionDescription)
    ' if action is started
    ElseIf actionDescription <> _currentActionDescriptionLevel1 Then
        ' remember action description
        _currentActionDescriptionLevel1 = actionDescription
        ' output action description with small indent
        System.Console.WriteLine("{0}...", actionDescription)
    End If
End Sub

''' <summary>
''' Outputs description of level 2 actions of font obfuscation.
''' </summary>
Private Shared Sub OnObfuscateProgressLevel2(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
    Dim actionDescription As String = e.Description
    ' if action is finished
    If e.Progress = 100 Then
        ' output action description with medium indent
        System.Console.WriteLine("    Finished ({0}).", actionDescription)
    ' if action is started
    ElseIf actionDescription <> _currentActionDescriptionLevel2 Then
        ' remember action description
        _currentActionDescriptionLevel2 = actionDescription
        ' output action description with medium indent
        System.Console.WriteLine("  {0}...", actionDescription)
    End If
End Sub

''' <summary>
''' Outputs description of level 3 actions of font obfuscation.
''' </summary>
Private Shared Sub OnObfuscateProgressLevel3(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
    Dim actionDescription As String = e.Description
    ' if action is finished
    If e.Progress = 100 Then
        ' output action description with large indent
        System.Console.WriteLine("        Finished ({0}).", actionDescription)
    ' if action is started
    ElseIf actionDescription <> _currentActionDescriptionLevel3 Then
        ' remember action description
        _currentActionDescriptionLevel3 = actionDescription
        ' output action description with large indent
        System.Console.WriteLine("      {0}...", actionDescription)
    End If
End Sub


/// <summary>
/// Stores current action description of level 1.
/// </summary>
static string _currentActionDescriptionLevel1 = null;

/// <summary>
/// Stores current action description of level 2.
/// </summary>
static string _currentActionDescriptionLevel2 = null;

/// <summary>
/// Stores current action description of level 3.
/// </summary>
static string _currentActionDescriptionLevel3 = null;

/// <summary>
/// Obfuscates encoding of all fonts of PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
/// <param name="resultFilename">The filename of resulting PDF document.</param>
public static void ObfuscateEncodingOfAllFontsWithDetailedInfo(
    string pdfFilename,
    string resultFilename)
{
    using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
    {
        // create obfuscator
        Vintasoft.Imaging.Pdf.PdfTextEncodingObfuscator textEncodingObfuscator = 
            new Vintasoft.Imaging.Pdf.PdfTextEncodingObfuscator();
        try
        {
            // create progress handler which handles 3 levels of progress
            Vintasoft.Imaging.Utils.IActionProgressHandler actionProgressHandler = 
                Vintasoft.Imaging.Utils.ActionProgressHandlers.CreateActionProgressHandler(
                    OnObfuscateProgressLevel1, OnObfuscateProgressLevel2, OnObfuscateProgressLevel3);
            // create progress controller
            Vintasoft.Imaging.Utils.ActionProgressController progressController = 
                new Vintasoft.Imaging.Utils.ActionProgressController(actionProgressHandler);
            // obfuscate all fonts
            textEncodingObfuscator.Obfuscate(document, progressController);
            // pack and save document to new location
            document.Pack(resultFilename);
        }
        catch (System.Exception ex)
        {
            System.Console.WriteLine(ex.Message);
        }
    }
}

/// <summary>
/// Outputs description of level 1 actions of font obfuscation.
/// </summary>
private static void OnObfuscateProgressLevel1(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
    string actionDescription = e.Description;
    // if action is finished
    if (e.Progress == 100)
    {
        // output action description with small indent
        System.Console.WriteLine("  Finished ({0}).", actionDescription);
    }
    // if action is started
    else if (actionDescription != _currentActionDescriptionLevel1)
    {
        // remember action description
        _currentActionDescriptionLevel1 = actionDescription;
        // output action description with small indent
        System.Console.WriteLine("{0}...", actionDescription);
    }
}

/// <summary>
/// Outputs description of level 2 actions of font obfuscation.
/// </summary>
private static void OnObfuscateProgressLevel2(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
    string actionDescription = e.Description;
    // if action is finished
    if (e.Progress == 100)
    {
        // output action description with medium indent
        System.Console.WriteLine("    Finished ({0}).", actionDescription);
    }
    // if action is started
    else if (actionDescription != _currentActionDescriptionLevel2)
    {
        // remember action description
        _currentActionDescriptionLevel2 = actionDescription;
        // output action description with medium indent
        System.Console.WriteLine("  {0}...", actionDescription);
    }
}

/// <summary>
/// Outputs description of level 3 actions of font obfuscation.
/// </summary>
private static void OnObfuscateProgressLevel3(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
    string actionDescription = e.Description;
    // if action is finished
    if (e.Progress == 100)
    {
        // output action description with large indent
        System.Console.WriteLine("        Finished ({0}).", actionDescription);
    }
    // if action is started
    else if (actionDescription != _currentActionDescriptionLevel3)
    {
        // remember action description
        _currentActionDescriptionLevel3 = actionDescription;
        // output action description with large indent
        System.Console.WriteLine("      {0}...", actionDescription);
    }
}

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also