Automatically rotate pages of a multipage TIFF file using OCR and VB.NET
This example shows how to automatically rotate pages of a multipage TIFF file with help of the OCR Tesseract engine method. After the successful rotation of all pages, the source file is saved to the destination file.
'We assume that GdPicture has been correctly installed and unlocked.Dim filepath As String = "multipage.tif"Dim destpath As String = "output.tif"'Specify your path.Dim DICT_PATH As String = "C:\GdPicture.NET 14\Redist\OCR"'Specify your language.Dim LANG As OCRLanguage = OCRLanguage.English
Dim status As GdPictureStatusUsing gdpictureImaging As New GdPictureImaging() Dim hasRotation As Boolean = False Dim imageID As Integer = gdpictureImaging.CreateGdPictureImageFromFile(filepath) status = gdpictureImaging.GetStat() If status = GdPictureStatus.OK Then Dim pageCount As Integer = gdpictureImaging.GetPageCount(imageID) For i As Integer = 1 To pageCount status = gdpictureImaging.SelectPage(imageID, i) If status = GdPictureStatus.OK Then Using gdpictureOCR As GdPictureOCR = New GdPictureOCR() gdpictureOCR.ResourceFolder = DICT_PATH gdpictureOCR.AddLanguage(LANG) status = gdpictureOCR.SetImage(imageID) Dim pageRotation As Integer = gdpictureOCR.GetOrientation() If pageRotation <> 0 Then hasRotation = True status = gdpictureImaging.RotateAngle(imageID, 360 - pageRotation) End If End Using End If If status <> GdPictureStatus.OK Then MessageBox.Show("Error: " + status, "Rotation + OCR Example", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit For End If Next If status = GdPictureStatus.OK Then If hasRotation Then status = gdpictureImaging.TiffSaveMultiPageToFile(imageID, destpath, TiffCompression.TiffCompressionAUTO) If status = GdPictureStatus.OK Then MessageBox.Show("Done!", "Rotation + OCR Example", MessageBoxButtons.OK, MessageBoxIcon.Information) Else MessageBox.Show("Error: " + status, "Rotation + OCR Example", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Else System.IO.File.Copy(filepath, destpath) End If End If gdpictureImaging.ReleaseGdPictureImage(imageID) End IfEnd Using
This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.