Reference Guide
Programming / Document Conversion / Converting a multipage TIFF file to a multipage JBIG2 file
In This Topic
    Converting a multipage TIFF file to a multipage JBIG2 file
    In This Topic

    This example shows you a quick way how to convert a multipage TIFF file to a multipage JBIG2 file.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    Dim tifffilepath As String = "multipage.tif"
    Dim jb2filepath As String = "multipage.jb2"
    Using oGdPictureImaging As New GdPictureImaging()
        Dim TiffID As Integer = oGdPictureImaging.CreateGdPictureImageFromFile(tifffilepath)
        If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
            Dim Jbig2ID As Integer = 0
            Dim pageCount As Integer = oGdPictureImaging.TiffGetPageCount(TiffID)
            For i As Integer = 1 To pageCount
                If i = 1 Then
                    Jbig2ID = oGdPictureImaging.CreateClonedGdPictureImage(TiffID)
                    If (oGdPictureImaging.GetStat() <> GdPictureStatus.OK) OrElse
                        (oGdPictureImaging.JBIG2SaveAsMultiPageFile(Jbig2ID, jb2filepath) <> GdPictureStatus.OK) Then
                        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Exit For
                    End If
                Else
                    If (oGdPictureImaging.TiffSelectPage(TiffID, i) <> GdPictureStatus.OK) OrElse
                        (oGdPictureImaging.JBIG2AddToMultiPageFile(Jbig2ID, TiffID) <> GdPictureStatus.OK) Then
                        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
                        Exit For
                    End If
                End If
            Next
            If oGdPictureImaging.GetStat() = GdPictureStatus.OK Then
                MessageBox.Show("Done!", "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
            oGdPictureImaging.JBIG2CloseMultiPageFile(Jbig2ID)
            oGdPictureImaging.ReleaseGdPictureImage(Jbig2ID)
            oGdPictureImaging.ReleaseGdPictureImage(TiffID)
        Else
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Using
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    string tifffilepath = "multipage.tif";
    string jb2filepath = "multipage.jb2";
    using (GdPictureImaging oGdPictureImaging = new GdPictureImaging())
    {
        int TiffID = oGdPictureImaging.CreateGdPictureImageFromFile(tifffilepath);
        if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
        {
            int Jbig2ID = 0;
            int pageCount = oGdPictureImaging.TiffGetPageCount(TiffID);
            for (int i = 1; i <= pageCount; i++)
            {
                if (i == 1)
                {
                    Jbig2ID = oGdPictureImaging.CreateClonedGdPictureImage(TiffID);
                    if ((oGdPictureImaging.GetStat() != GdPictureStatus.OK) ||
                        (oGdPictureImaging.JBIG2SaveAsMultiPageFile(Jbig2ID, jb2filepath) != GdPictureStatus.OK))
                    {
                        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                }
                else
                {
                    if ((oGdPictureImaging.TiffSelectPage(TiffID, i) != GdPictureStatus.OK) ||
                        (oGdPictureImaging.JBIG2AddToMultiPageFile(Jbig2ID, TiffID) != GdPictureStatus.OK))
                    {
                        MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                }
            }
            if (oGdPictureImaging.GetStat() == GdPictureStatus.OK)
                MessageBox.Show("Done!", "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
            oGdPictureImaging.JBIG2CloseMultiPageFile(Jbig2ID);
            oGdPictureImaging.ReleaseGdPictureImage(Jbig2ID);
            oGdPictureImaging.ReleaseGdPictureImage(TiffID);
        }
        else
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "TIFF to JBIG2 Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }