EnableCompression Method (GdPicturePDF)
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.
public void EnableCompression(
bool
)
public procedure EnableCompression(
: Boolean
);
public function EnableCompression(
: boolean
);
public: void EnableCompression(
bool
)
public:
void EnableCompression(
bool
)
'Declaration
Public Sub EnableCompression( _
ByVal As Boolean _
)
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.
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);
}
}