VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
Vintasoft.Imaging.Pdf Namespace / PdfTextEncodingObfuscator Class / Obfuscate Methods / Obfuscate(PdfDocument,IActionProgressController) Method
Синтаксис Exceptions Ремарки Example Требования Смотрите также
В этом разделе
    Obfuscate(PdfDocument,IActionProgressController) Метод (PdfTextEncodingObfuscator)
    В этом разделе
    Затеняет кодировки всех шрифтов, содержащихся в указанном PDF документе.
    Синтаксис

    Parameters

    document
    Документ PDF.
    progressController
    Контроллер хода выполнения.
    Исключения
    ИсключениеОписание
    Выбрасывается, если document имеет значение null.
    Выбрасывается, если document содержит внешние шрифты.
    Выбрасывается, если документ содержит шрифты, которые не поддерживаются для запутывания.
    Ремарки

    В настоящее время этот метод не поддерживает запутывание шрифтов Type3, которые используют другие шрифты в качестве ресурсов или которые используются в качестве ресурсов.

    Пример

    Вот пример, показывающий, как скрыть кодировку встроенных шрифтов в PDF документе и вывести подробную информацию о ходе выполнения на консоль:

    
    ''' <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);
        }
    }
    
    

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также