---
title: "Deskew PDF and images in C# .NET | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/ocr/preprocess/deskew/"
md_url: "https://www.nutrient.io/guides/dotnet/ocr/preprocess/deskew.md"
last_updated: "2026-05-21T17:12:02.207Z"
description: "Learn how to deskew scanned PDFs and images in C# using Nutrient .NET SDK. Correct document skew and improve optical character recognition (OCR) results with our guide."
---

# Deskew PDFs and images in C#

After scanning a physical document, the resulting image can be slightly rotated or skewed. Skewed images are difficult to read. This guide explains how to compensate for small rotations in a document by deskewing an image.

The images below show what a document looks like before and after deskewing.![Skewed before image](@/assets/guides/dotnet/ocr/preprocess/skewed.png)![Deskewed after image](@/assets/guides/dotnet/ocr/preprocess/deskewed.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 deskew an image, 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. Deskew the image with the `AutoDeskew` method of the `GdPictureImaging` object. This method takes the following parameters:
   1. The image ID.
   2. Optional: The maximum angle of rotation in the image. Images rotated by a larger angle aren’t deskewed. As such, this parameter is useful if you suspect that some images are accidentally skewed by a smaller angle and some images are intentionally rotated by a larger angle; you want to deskew the first group, but not the second. If you don’t specify this parameter, the maximum angle of rotation is 15 degrees 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 automatically deskews a document:

### C#

```csharp

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load the image from a file.
int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:/temp/source.png");
// Deskew the image.
gdpictureImaging.AutoDeskew(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")
    ' Deskew the image.
    gdpictureImaging.AutoDeskew(imageId)
    ' Save the output in a new image.
    gdpictureImaging.SaveAsPNG(imageId, "C:/temp/output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageId)
End Using

```

The example below automatically deskews an image if the angle of rotation is less than 10 degrees:

### C#

```csharp

using GdPictureImaging gdpictureImaging = new GdPictureImaging();
// Load the image from a file.
int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:/temp/source.png");
// Deskew the image.
gdpictureImaging.AutoDeskew(imageId, 10);
// 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")
    ' Deskew the image.
    gdpictureImaging.AutoDeskew(imageId, 10)
    ' Save the output in a new image.
    gdpictureImaging.SaveAsPNG(imageId, "C:/temp/output.png")
    gdpictureImaging.ReleaseGdPictureImage(imageId)
End Using

```

#### Used methods

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

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

- [`ReleaseGdPictureImage`](/api/gdpicture/GdPicture.NET.14~GdPicture14.GdPictureImaging~ReleaseGdPictureImage.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)
- [Auto-invert images and PDFs in C#](/guides/dotnet/ocr/preprocess/auto-invert.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)
- [Image preprocessing and OCR accuracy in C#](/guides/dotnet/ocr/preprocess.md)
- [Remove punch holes from images and PDFs in C#](/guides/dotnet/ocr/preprocess/remove-punch-holes.md)

