In This Topic
Programming / Document Cleanup / Removing punch holes

Removing punch holes

In This Topic

Punch holes can be easily interpreted as letters by OCR. It is very important to clean them from your images. They can also be an eye sore making your documents look unprofessional and old.

Before / After

There are two ways you can remove punch holes:

  1. By assuming that the hole punches are on the left side, which is where most documents have them.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    
     Dim oGdPictureImaging As New GdPictureImaging()
    
     'Loading the image from a file.
    
     Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif")
    
     'Checking if the image resource has been loaded correctly.
    
     If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
    
         MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
     Else
    
       'Now you clean up your punch holes.
    
        Dim status As GdPictureStatus = oGdPictureImaging.RemoveHolePunch(imageId)
    
        If status <> GdPictureStatus.OK Then
    
             MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
         Else
    
            'After you are done with your processing, you can save the image.
    
             status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO)
    
             If status <> GdPictureStatus.OK Then
    
                 MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
             End If
    
         End If
    
         oGdPictureImaging.ReleaseGdPictureImage(imageId)
    
     End If
    
     oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    //Loading the image from a file.
    
    int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif");
    
    //Checking if the image resource has been loaded correctly.
    
    if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
    
    {
    
        MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    }
    
    else
    
    {
    
        //Now you clean up your punch holes.
    
        GdPictureStatus status = oGdPictureImaging.RemoveHolePunch(imageId);
    
        if (status != GdPictureStatus.OK)
    
        {
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        }
    
        else
    
        {
    
            //After you are done with your processing, you can save the image.
    
            status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO);
    
            if (status != GdPictureStatus.OK)
    
            {
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
            }
    
        }
    
        oGdPictureImaging.ReleaseGdPictureImage(imageId);
    
    }
    
    oGdPictureImaging.Dispose();
  2. If you know, that the punch holes are on another margin, or could be in any margin, you can specify the margin or more by "ORing" them as follows.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    
     Dim oGdPictureImaging As New GdPictureImaging()
    
     'Loading the image from a file.
    
     Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif")
    
     'Checking if the image resource has been loaded correctly.
    
     If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
    
         MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
     Else
    
       'Now you clean up your punch holes.
    
        Dim status As GdPictureStatus = oGdPictureImaging.RemoveHolePunch(imageId, HolePunchMargins.MarginLeft Or HolePunchMargins.MarginRight Or HolePunchMargins.MarginTop Or HolePunchMargins.MarginBottom)
    
        If status <> GdPictureStatus.OK Then
    
             MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
         Else
    
            'After you are done with your processing, you can save the image.
    
             status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO)
    
             If status <> GdPictureStatus.OK Then
    
                 MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
             End If
    
         End If
    
         oGdPictureImaging.ReleaseGdPictureImage(imageId)
    
     End If
    
     oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    
    //Loading the image from a file.
    
    int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif");
    
    //Checking if the image resource has been loaded correctly.
    
    if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
    
    {
    
        MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
    }
    
    else
    
    {
    
        //Now you clean up your punch holes.
    
        GdPictureStatus status = oGdPictureImaging.RemoveHolePunch(imageId, HolePunchMargins.MarginLeft | HolePunchMargins.MarginRight | HolePunchMargins.MarginTop | HolePunchMargins.MarginBottom);
    
        if (status != GdPictureStatus.OK)
    
        {
    
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
        }
    
        else
    
        {
    
            //After you are done with your processing, you can save the image.
    
            status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO);
    
            if (status != GdPictureStatus.OK)
    
            {
    
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Document Cleanup Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    
            }
    
        }
    
        oGdPictureImaging.ReleaseGdPictureImage(imageId);
    
    }
    
    oGdPictureImaging.Dispose();