GdPicture.NET.14.API
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
The GdPicturePDF.GetStat method can be subsequently used 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 gdpicturePDF As New GdPicturePDF()
    Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
    If status = GdPictureStatus.OK Then
        gdpicturePDF.EnableCompression(True)
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If gdpicturePDF.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
        gdpicturePDF.EnableCompression(False)
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            If gdpicturePDF.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 gdpicturePDF = new GdPicturePDF())
{
    GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        gdpicturePDF.EnableCompression(true);
        status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if (gdpicturePDF.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);
        }
        gdpicturePDF.EnableCompression(false);
        status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            if (gdpicturePDF.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