A member of the PdfCompression enumeration. The new compression scheme to be used.
Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / SetCompressionForBitonalImage Method

SetCompressionForBitonalImage Method (GdPicturePDF)

In This Topic
Sets the scheme to be used to compress bitonal image data within the currently loaded PDF document.

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 SetCompressionForBitonalImage( _

   ByVal Compression As PdfCompression _

) 
public void SetCompressionForBitonalImage( 

   PdfCompression Compression

)
public procedure SetCompressionForBitonalImage( 

    Compression: PdfCompression

); 
public function SetCompressionForBitonalImage( 

   Compression : PdfCompression

);
public: void SetCompressionForBitonalImage( 

   PdfCompression Compression

) 
public:

void SetCompressionForBitonalImage( 

   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.
Example
How to set the image compression correctly.
Dim caption As String = "Example: SetCompressionForBitonalImage"

Dim oImage As GdPictureImaging = New GdPictureImaging()

Dim imageID As Integer = oImage.CreateGdPictureImageFromFile("input.tif")

If oImage.GetStat() = GdPictureStatus.OK Then

    Dim count As Integer = oImage.GetPageCount(imageID)

    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.SetCompressionForBitonalImage(PdfCompression.PdfCompressionCCITT4)

            Dim status As GdPictureStatus = gdpicturePDF.GetStat()

            If status = GdPictureStatus.OK Then

                'Process your document.

                For i As Integer = 1 To count

                    status = oImage.SelectPage(imageID, i)

                    If status = GdPictureStatus.OK Then

                        status = gdpicturePDF.AddImageFromGdPictureImage(imageID, PdfAdvancedImageCompression.PdfAdvancedImageCompressionNone)

                        If status <> GdPictureStatus.OK Then

                            MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + status.ToString(), caption)

                            Exit For

                        End If

                    Else

                        MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption)

                        Exit For

                    End If

                Next

                'Check, if all is done without errors.

                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

                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 GetPageCount() method has failed with the status: " + oImage.GetStat().ToString(), caption)

    End If

Else

    MessageBox.Show("The image can't be created. Status: " + oImage.GetStat().ToString(), caption)

End If
string caption = "Example: SetCompressionForBitonalImage";

GdPictureImaging oImage = new GdPictureImaging();

int imageID = oImage.CreateGdPictureImageFromFile("input.tif");

if (oImage.GetStat() == GdPictureStatus.OK)

{

    int count = oImage.GetPageCount(imageID);

    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.SetCompressionForBitonalImage(PdfCompression.PdfCompressionCCITT4);

            GdPictureStatus status = gdpicturePDF.GetStat();

            if (status == GdPictureStatus.OK)

            {

                //Process your document.

                for (int i = 1; i <= count; i++)

                {

                    status = oImage.SelectPage(imageID, i);

                    if (status == GdPictureStatus.OK)

                    {

                        status = gdpicturePDF.AddImageFromGdPictureImage(imageID, PdfAdvancedImageCompression.PdfAdvancedImageCompressionNone);

                        if (status != GdPictureStatus.OK)

                        {

                            MessageBox.Show("The AddImageFromGdPictureImage() method has failed with the status: " + status.ToString(), caption);

                            break;

                        }

                    }

                    else

                    {

                        MessageBox.Show("The SelectPage() method has failed with the status: " + status.ToString(), caption);

                        break;

                    }

                }

                //Check, if all is done without errors.

                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 SetCompressionForBitonalImage() 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 GetPageCount() method has failed with the status: " + oImage.GetStat().ToString(), caption);

}

else

    MessageBox.Show("The image can't be created. Status: " + oImage.GetStat().ToString(), caption);
See Also