VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Pdf Namespace / PdfTextEncodingObfuscator Class
Members Example



In This Topic
    PdfTextEncodingObfuscator Class
    In This Topic
    Obfuscates text encodings in fonts of PDF document.
    Object Model
    PdfTextEncodingObfuscator Class
    Syntax
    'Declaration
     
    Public Class PdfTextEncodingObfuscator 
    public class PdfTextEncodingObfuscator 
    public __gc class PdfTextEncodingObfuscator 
    public ref class PdfTextEncodingObfuscator 
    Remarks
    Obfuscation of text encoding consists from 2 steps:
    • Unicode codes of symbols are removed from font
    • Font program is changed randomly (glyphs are rearranged; not used glyphs are removed; duplicate glyphs are added; etc).

    Text search and text extraction will be not possible after the text encoding obfuscation - extracted text will contain "garbage". PDF page view will not be changed after obfuscation, i.e. PDF page view before and after obfuscation are the same.

    Current version supports obfuscation of TrueType, Type1 and Type3 fonts.
    A System.NotSupportedException will be thrown whenever an unsupported font is encountered during obfuscation.
    A System.InvalidOperationException will be thrown whenever an external font is encountered during obfuscation.

    Important! - PDF document must be packed (PdfDocument.Pack) after text encoding obfuscation otherwise the original encodings can be restored.
    This class adds the following string resources in Vintasoft.Imaging.ImagingEnvironment.ResourceManager
    • "PDFTEXTENCODINGOBFUSCATOR_OBFUSCATE" = "Obfuscate text encoding"
    • "PDFTEXTENCODINGOBFUSCATOR_GET_USED_SYMBOLS" = "Get used symbols"
    • "PDFTEXTENCODINGOBFUSCATOR_CREATE_OBFUSCATED_FONT_SUBSET" = "Create obfuscated font subsets"
    • "PDFTEXTENCODINGOBFUSCATOR_GET_LIST_OF_FONTS" = "Get list of fonts"
    • "PDFTEXTENCODINGOBFUSCATOR_REPLACE_TEXT_SYMBOLS" = "Replace text symbols"
    • "PDFTEXTENCODINGOBFUSCATOR_FONTS_NOT_CHANGED" = "Fonts are not changed"
    • "PDFTEXTENCODINGOBFUSCATOR_FONTS_OBFUSCATED" = "Fonts are obfuscated"
    • "PDFTEXTENCODINGOBFUSCATOR_FONT_OBFUSCATION_ERROR_{0}" = "Fonts obfuscation error: {0}"
    Example
    This example shows how to obfuscate the encoding of embedded fonts in PDF document.
    ''' <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 ObfuscateEncodingOfAllFonts(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
                ' obfuscate all fonts
                textEncodingObfuscator.Obfuscate(document)
                ' 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>
    /// 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 ObfuscateEncodingOfAllFonts(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
            {
                // obfuscate all fonts
                textEncodingObfuscator.Obfuscate(document);
                // pack and save document to new location
                document.Pack(resultFilename);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Pdf.PdfTextEncodingObfuscator

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also