GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / SetCompressionForColorImage Method
A member of the PdfCompression enumeration. The new compression scheme to be used.
Example





In This Topic
SetCompressionForColorImage Method (GdPicturePDF)
In This Topic
Sets the scheme to be used to compress color image data within the currently loaded PDF document. The default value is PdfCompression.PdfCompressionJPEG.

Please note that firstly you need to create or load the PDF document to allow this setting to work properly. Secondly, you need to set the compression scheme before adding the required image to the current document.

Syntax
'Declaration
 
Public Sub SetCompressionForColorImage( _
   ByVal Compression As PdfCompression _
) 
public void SetCompressionForColorImage( 
   PdfCompression Compression
)
public procedure SetCompressionForColorImage( 
    Compression: PdfCompression
); 
public function SetCompressionForColorImage( 
   Compression : PdfCompression
);
public: void SetCompressionForColorImage( 
   PdfCompression Compression
) 
public:
void SetCompressionForColorImage( 
   PdfCompression Compression
) 

Parameters

Compression
A member of the PdfCompression enumeration. The new compression scheme to be used.
Remarks
It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any. Please ensure that you have successfully created or loaded a PDF document, otherwise the method does nothing.

Be aware that if you select the PdfCompression.PdfCompressionCCITT4 or PdfCompression.PdfCompressionJBIG2, the deflate compression will be used instead.

Example
How to set the image compression correctly.
Dim caption As String = "Example: SetCompressionForColorImage"
Dim oImage As GdPictureImaging = New GdPictureImaging()
Dim imageID As Integer = oImage.CreateGdPictureImageFromFile("input.jpg")
If oImage.GetStat() = GdPictureStatus.OK Then
    Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    'Firstly, create or load the PDF document.
    If gdpicturePDF.NewPDF() = GdPictureStatus.OK Then
        'Secondly, set the required compression.
        gdpicturePDF.SetCompressionForColorImage(PdfCompression.PdfCompressionJPEG2000)
        Dim status As GdPictureStatus = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            'Process your document.
            status = gdpicturePDF.AddImageFromGdPictureImage(imageID, PdfAdvancedImageCompression.PdfAdvancedImageCompressionNone)
            If status = GdPictureStatus.OK Then
                'At the end, save the file with the previously selected compression.
                If gdpicturePDF.SaveToFile("output.pdf", False) = GdPictureStatus.OK Then
                    MessageBox.Show("Done!", caption)
                Else
                    MessageBox.Show("The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + status.ToString(), caption)
            End If
        Else
            MessageBox.Show("The SetCompressionForBitonalImage() method has failed with the status: " + status.ToString(), caption)
        End If
    Else
        MessageBox.Show("The new PDF document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The image can't be created. Status: " + oImage.GetStat().ToString(), caption)
End If
string caption = "Example: SetCompressionForColorImage";
GdPictureImaging oImage = new GdPictureImaging();
int imageID = oImage.CreateGdPictureImageFromFile("input.jpg");
if (oImage.GetStat() == GdPictureStatus.OK)
{
    GdPicturePDF gdpicturePDF = new GdPicturePDF();
    //Firstly, create or load the PDF document.
    if (gdpicturePDF.NewPDF() == GdPictureStatus.OK)
    {
        //Secondly, set the required compression.
        gdpicturePDF.SetCompressionForColorImage(PdfCompression.PdfCompressionJPEG2000);
        GdPictureStatus status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            //Process your document.
            status = gdpicturePDF.AddImageFromGdPictureImage(imageID, PdfAdvancedImageCompression.PdfAdvancedImageCompressionNone);
            if (status == GdPictureStatus.OK)
            {
                //At the end, save the file with the previously selected compression.
                if (gdpicturePDF.SaveToFile("output.pdf", false) == GdPictureStatus.OK)
                    MessageBox.Show("Done!", caption);
                else
                    MessageBox.Show("The file can't be saved. Status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
            else
            {
                MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + status.ToString(), caption);
            }
        }
        else
            MessageBox.Show("The SetCompressionForColorImage() method has failed with the status: " + status.ToString(), caption);
    }
    else
        MessageBox.Show("The new PDF document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
else
    MessageBox.Show("The image can't be created. Status: " + oImage.GetStat().ToString(), caption);
See Also