VintaSoft Imaging .NET SDK 14.1: Documentation for .NET developer
Vintasoft.Imaging.Pdf Namespace / PdfFontManager Class / PackAllFonts Methods / PackAllFonts(IActionProgressController) Method
Syntax Example Requirements SeeAlso
    PackAllFonts(IActionProgressController) Method (PdfFontManager)
    Packs all fonts of PDF document.
    Syntax

    Parameters

    progressController
    Progress controller.

    Return Value

    True - font programs are packed successfully;
    false - font programs are NOT packed.
    Example

    Here is an example that shows how to pack all fonts of 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>
    ''' Removes all unused characters from fonts of PDF document
    ''' and outputs detailed progress info to the console.
    ''' </summary>
    ''' <param name="pdfFilename">The filename of PDF document.</param>
    ''' <param name="resultFilename">The filename of resulting PDF document.</param>
    Public Shared Sub PackAllFontsOfDocumentWithDetailedInfo(pdfFilename As String, resultFilename As String)
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
            ' create progress handler which handles 3 levels of progress
            Dim actionProgressHandler As Vintasoft.Imaging.Utils.IActionProgressHandler = Vintasoft.Imaging.Utils.ActionProgressHandlers.CreateActionProgressHandler(AddressOf OnPackProgressLevel1, AddressOf OnPackProgressLevel2, AddressOf OnPackProgressLevel3)
            ' create progress controller
            Dim progressController As New Vintasoft.Imaging.Utils.ActionProgressController(actionProgressHandler)
            ' pack all fonts using progress controller
            document.FontManager.PackAllFonts(progressController)
            ' pack and save document to new location
            document.Pack(resultFilename)
        End Using
    End Sub
    
    ''' <summary>
    ''' Outputs description of level 1 actions of font packing.
    ''' </summary>
    Private Shared Sub OnPackProgressLevel1(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 packing.
    ''' </summary>
    Private Shared Sub OnPackProgressLevel2(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 packing.
    ''' </summary>
    Private Shared Sub OnPackProgressLevel3(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>
    /// Removes all unused characters from fonts of PDF document
    /// and outputs detailed progress info to the console.
    /// </summary>
    /// <param name="pdfFilename">The filename of PDF document.</param>
    /// <param name="resultFilename">The filename of resulting PDF document.</param>
    public static void PackAllFontsOfDocumentWithDetailedInfo(string pdfFilename, string resultFilename)
    {
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
        {
            // create progress handler which handles 3 levels of progress
            Vintasoft.Imaging.Utils.IActionProgressHandler actionProgressHandler = 
                Vintasoft.Imaging.Utils.ActionProgressHandlers.CreateActionProgressHandler(
                    OnPackProgressLevel1, OnPackProgressLevel2, OnPackProgressLevel3);
            // create progress controller
            Vintasoft.Imaging.Utils.ActionProgressController progressController = 
                new Vintasoft.Imaging.Utils.ActionProgressController(actionProgressHandler);
            // pack all fonts using progress controller
            document.FontManager.PackAllFonts(progressController);
            // pack and save document to new location
            document.Pack(resultFilename);
        }
    }
    
    /// <summary>
    /// Outputs description of level 1 actions of font packing.
    /// </summary>
    private static void OnPackProgressLevel1(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 packing.
    /// </summary>
    private static void OnPackProgressLevel2(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 packing.
    /// </summary>
    private static void OnPackProgressLevel3(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: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also