Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / EnableCompression Method
Set this parameter to true if you want to compress the PDF document during each save process. Enabling the compression will allow the toolkit to compress the content of your currently loaded PDF document using the Deflate Algorithm.

If you set this parameter to false, the PDF document will remain uncompressed after the save process.

Example





In This Topic
    EnableCompression Method (GdPicturePDF)
    In This Topic
    Sets the parameter for the current GdPicturePDF object that specifies if PDF documents will be compressed during the save process. The result of this compression is a smaller file size. The compression is enabled by default for each newly created GdPicturePDF object.

    Heavy text and image content can considerably increase the size of the PDF document. During the compression process, the toolkit will remove unused objects and elements. This leads to a significantly reduced file size. Therefore the compression is particularly valuable for large images. This drastic reduction however does not affect any of the file's content but it will make your PDF files compact and easy to open.

    The list of compression algorithms is extensive, for example, JPEG, JPEG2000 or JBIG2 for images, Flate or LZW for text as well as images, etc. The toolkit offers the Deflate compression algorithm.

    Syntax
    'Declaration
     
    
    Public Sub EnableCompression( _
       ByVal Compress As Boolean _
    ) 
    public void EnableCompression( 
       bool Compress
    )
    public procedure EnableCompression( 
        Compress: Boolean
    ); 
    public function EnableCompression( 
       Compress : boolean
    );
    public: void EnableCompression( 
       bool Compress
    ) 
    public:
    void EnableCompression( 
       bool Compress
    ) 

    Parameters

    Compress
    Set this parameter to true if you want to compress the PDF document during each save process. Enabling the compression will allow the toolkit to compress the content of your currently loaded PDF document using the Deflate Algorithm.

    If you set this parameter to false, the PDF document will remain uncompressed after the save process.

    Remarks
    Please always use the GetStat method to determine if this method has been successful.

    The deflate data compression algorithm, which we support, is a lossless type of compression, that can reduce files without a loss of information in the process. The original file can be then recreated exactly when uncompressed. On the other hand, the opposite approach is lossy compression, that reduces the file size by permanently deleting any unnecessary data. However, the original file can't be retained.

    Example
    How to enable and disable PDF compression.
    Dim caption As String = "Example: EnableCompression"
    Using oGdPicturePDF As New GdPicturePDF()
        Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("test.pdf", False)
        If status = GdPictureStatus.OK Then
            oGdPicturePDF.EnableCompression(True)
            status = oGdPicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                If oGdPicturePDF.SaveToFile("test_EnableCompression.pdf") = GdPictureStatus.OK Then
                    MessageBox.Show("The file has been successfully compressed and saved.", caption)
                End If
            Else
                MessageBox.Show("The EnableCompression() method has failed with the status: " + status.ToString(), caption)
            End If
            oGdPicturePDF.EnableCompression(False)
            status = oGdPicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                If oGdPicturePDF.SaveToFile("test_DisableCompression.pdf") = GdPictureStatus.OK Then
                    MessageBox.Show("The file has been successfully saved without compression.", caption)
                End If
            Else
                MessageBox.Show("The EnableCompression() method has failed with the status: " + status.ToString(), caption)
            End If
        Else
            MessageBox.Show("The file can't be loaded.", caption)
        End If
    End Using
    string caption = "Example: EnableCompression";
    using (GdPicturePDF oGdPicturePDF = new GdPicturePDF())
    {
        GdPictureStatus status = oGdPicturePDF.LoadFromFile("test.pdf", false);
        if (status == GdPictureStatus.OK)
        {
            oGdPicturePDF.EnableCompression(true);
            status = oGdPicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if (oGdPicturePDF.SaveToFile("test_EnableCompression.pdf") == GdPictureStatus.OK)
                {
                    MessageBox.Show("The file has been successfully compressed and saved.", caption);
                }
            }
            else
            {
                MessageBox.Show("The EnableCompression() method has failed with the status: " + status.ToString(), caption);
            }
            oGdPicturePDF.EnableCompression(false);
            status = oGdPicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                if (oGdPicturePDF.SaveToFile("test_DisableCompression.pdf") == GdPictureStatus.OK)
                {
                    MessageBox.Show("The file has been successfully saved without compression.", caption);
                }
            }
            else
            {
                MessageBox.Show("The EnableCompression() method has failed with the status: " + status.ToString(), caption);
            }
        }
        else
        {
            MessageBox.Show("The file can't be loaded.", caption);
        }
    }
    See Also