Convert a multipage TIFF to a multipage JBIG2 in VB.NET

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


VB.NET
'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

This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.