---
title: "Remove punch holes from images and PDFs in C# .NET | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/ocr/preprocess/remove-punch-holes/"
md_url: "https://www.nutrient.io/guides/dotnet/ocr/preprocess/remove-punch-holes.md"
last_updated: "2026-05-15T19:10:04.992Z"
description: "Learn how to remove punch holes from images and PDFs in C# using Nutrient .NET SDK. Clean up scanned documents for improved optical character recognition (OCR) accuracy."
---

# Remove punch holes from images and PDFs in C#

Physical documents can have punch holes used to bind sheets of paper together. In scans of physical documents, punch holes make pages difficult to read. This article explains how to automatically remove punch holes from your images and PDF documents.

The images below show what a document looks like before and after removing punch holes.![Before removing punch holes](@/assets/guides/dotnet/ocr/preprocess/hole-punch-before.png)![After removing punch holes](@/assets/guides/dotnet/ocr/preprocess/hole-punch-after.png)

Don’t preprocess documents before recognizing text with OCR. Nutrient.NET SDK’s OCR engine preprocesses documents automatically with better results than manual preprocessing.

To automatically detect punch holes in a document and remove them, follow the steps below:

1. Create a `GdPictureImaging` object.

2. Select the image by passing its path to the `CreateGdPictureImageFromFile` method of the `GdPictureImaging` object.

3. Remove the punch holes with the `RemoveHolePunch` method of the `GdPictureImaging` object. This method takes the following parameters:
   1. The image ID.
   2. Optional: Members of the `HolePunchMargins` enumeration, separated by vertical bar `|` characters. This parameter specifies the sides of the page from which the punch holes are removed. If you don’t specify this parameter, punch holes are removed from the left side of the page by default.

4. Save the output in a new image with the `SaveAsPNG` method of the `GdPictureImaging` object.

5. Release the image resource with the `ReleaseGdPictureImage` method of the `GdPictureImaging` object.

The example below removes punch holes from the left side of the page:

### C#

```csharp

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load the image from a file.
int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:/temp/source.png");
// Remove the punch holes.
gdpictureImaging.RemoveHolePunch(imageId);
// Save the output in a new image.
gdpictureImaging.SaveAsPNG(imageId, @"C:/temp/output.png");
gdpictureImaging.ReleaseGdPictureImage(imageId);

```

### VB.NET

```vb

Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load the image from a file.
    Dim imageId As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:/temp/source.png")
    ' Remove the punch holes.
    gdpictureImaging.RemoveHolePunch(imageId)
    ' Save the output in a new image.
    gdpictureImaging.SaveAsPNG(imageId, "C:/temp/output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageId)
End Using

```

The example below removes punch holes from the left and right sides of the page:

### C#

```csharp

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load the image from a file.
int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:/temp/source.png");
// Remove the punch holes.
gdpictureImaging.RemoveHolePunch(imageId, HolePunchMargins.MarginLeft | HolePunchMargins.MarginRight);
// Save the output in a new image.
gdpictureImaging.SaveAsPNG(imageId, @"C:/temp/output.png");
gdpictureImaging.ReleaseGdPictureImage(imageId);

```

### VB.NET

```vb

Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
    ' Load the image from a file.
    Dim imageId As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:/temp/source.png")
    ' Remove the punch holes.
    gdpictureImaging.RemoveHolePunch(imageId, HolePunchMargins.MarginLeft | HolePunchMargins.MarginRight)
    ' Save the output in a new image.
    gdpictureImaging.SaveAsPNG(imageId, "C:/temp/output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageId)
End Using

```

#### Used methods and properties

- [`CreateGdPictureImageFromFile`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureImaging~CreateGdPictureImageFromFile.html)

- [`ReleaseGdPictureImage`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureImaging~ReleaseGdPictureImage.html)

- [`RemoveHolePunch`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureImaging~RemoveHolePunch.html)

- [`SaveAsPNG`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureImaging~SaveAsPNG.html)

#### Related topics

- [Load a file](/guides/dotnet/load-a-file.md)

- [Save a file](/guides/dotnet/save-a-file.md)

---

## Related pages

- [Remove lines from images and PDFs in C#](/guides/dotnet/ocr/preprocess/remove-lines.md)
- [Image preprocessing and OCR accuracy in C#](/guides/dotnet/ocr/preprocess.md)
- [Deskew PDFs and images in C#](/guides/dotnet/ocr/preprocess/deskew.md)
- [Remove noise from images in C#](/guides/dotnet/ocr/preprocess/remove-noise.md)
- [Enhance characters in PDFs and images in C#](/guides/dotnet/ocr/preprocess/enhance-characters.md)
- [Auto-invert images and PDFs in C#](/guides/dotnet/ocr/preprocess/auto-invert.md)

