Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / PackFonts Method
Example





In This Topic
    PackFonts Method (GdPicturePDF)
    In This Topic
    Optimizes fonts used in the currently loaded PDF document in order to minimize its file size for archiving.

    This method is useful primarily for PDF documents intended for storing or archiving to reduce its file size. The toolkit replaces the fully embedded fonts included in the document with their corresponding subsets and removes all other unnecessary data found in the existing font files as well. Be aware that subsequent editing of such optimized document may lead to insufficient rendering.

    Syntax
    'Declaration
     
    
    Public Function PackFonts() As GdPictureStatus
    public GdPictureStatus PackFonts()
    public function PackFonts(): GdPictureStatus; 
    public function PackFonts() : GdPictureStatus;
    public: GdPictureStatus PackFonts(); 
    public:
    GdPictureStatus PackFonts(); 

    Return Value

    A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

    We strongly recommend always checking this status first.

    Remarks
    Please note that this method is only allowed for use with non-encrypted documents.

    Just to inform you, that embedded font programs used in the document are subsetted and any unnecessary duplicity in font resources structure is removed. This method is mainly useful when you need to reduce the file size of the final stage of the PDF document. It is not suitable when you need to edit this document further.

    Example
    How to simply optimize fonts in the PDF document.
    Dim caption As String = "Example: PackFonts"
    Using oGdPicturePDF As GdPicturePDF = New GdPicturePDF()
        If oGdPicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
            If oGdPicturePDF.PackFonts() = GdPictureStatus.OK Then
                If oGdPicturePDF.SaveToFile("test_optimized.pdf") = GdPictureStatus.OK Then
                    MessageBox.Show("The example has been followed successfully.", caption)
                Else
                    MessageBox.Show("The file can't be saved. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The error occurs when optimizing fonts. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The file can't be opened. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
        End If
    End Using
    string caption = "Example: PackFonts";
    using (GdPicturePDF oGdPicturePDF = new GdPicturePDF())
    {
        if (oGdPicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
        {
            if (oGdPicturePDF.PackFonts() == GdPictureStatus.OK)
            {
                if (oGdPicturePDF.SaveToFile("test_optimized.pdf") == GdPictureStatus.OK)
                {
                    MessageBox.Show("The example has been followed successfully.", caption);
                }
                else
                {
                    MessageBox.Show("The file can't be saved. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
                }
            }
            else
            {
                MessageBox.Show("The error occurs when optimizing fonts. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
            }
        }
        else
        {
            MessageBox.Show("The file can't be opened. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
        }
    }
    See Also