IRONSOFTWAREHOME

How to Set DPI in OCR Using C#

Curtis Chau
Curtis Chau
Updated: August 2, 2026

Set the TargetDPI property in IronOCR's OcrInput to upscale low-resolution images for better OCR accuracy. This configuration can significantly improve text recognition on blurry or pixelated documents, even with resolutions as low as 100 DPI.

Dots Per Inch (DPI) measures image quality and determines the level of detail in scanned documents or digital photographs. While scanning documents is fast and efficient, the process often results in low-resolution files, especially when using default or quick scan settings. This lack of detail makes text appear blurry or pixelated, creating obstacles for data extraction.

OCR performance depends on image quality. OCR engines analyze character shapes and patterns to convert them into machine-readable text. When an image has low DPI, there aren't enough pixels to clearly define each letter, causing fine details to be lost and leading to inaccurate results. For developers working with scanned documents or legacy digitization systems, understanding DPI optimization is crucial for reliable text extraction.

IronOCR handles these challenges effectively. It achieves high accuracy on scans with resolutions as low as 225 DPI. The library's image preprocessing capabilities automatically detect and compensate for various image quality issues, making it suitable for processing documents from diverse sources. Whether implementing simple OCR in one line of code or building complex document processing pipelines, DPI optimization remains a critical factor.

Quickstart: Set TargetDPI for Sharper OCR Results

Configure IronOCR to upscale low-resolution images in one line - improving text clarity and recognition with minimal effort.

  1. 1Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. 2Copy and run this code snippet.

    var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrInput { TargetDPI = 300 }.LoadImage("low-res.png"));
    C#
  3. 3Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer

How Do I Set DPI for Better OCR Results?

This example uses a sample image with a low resolution of approximately 100 DPI and adds artificial noise to demonstrate the effectiveness of the TargetDPI feature. Understanding how to configure DPI settings is essential when working with the OcrInput class, which provides comprehensive control over image preprocessing.

The actual text in the image is: "Testing testing testing blurry text example example example".

Low-resolution 100 DPI sample showing blurry, pixelated text demonstrating poor OCR input quality

What Code Do I Need to Upscale Image DPI?

In this example, we'll set the TargetDPI to 300 to upscale the image resolution. Then we'll load the input image and print the extracted text with Text and the confidence level with Confidence. The optimal DPI setting typically ranges between 250-400 DPI, depending on your use case and source material quality. For advanced scenarios involving multiple image filters, refer to our guide on OCR image optimization filters.

using IronOcr;
using System;

var ocrTesseract = new IronTesseract();

using var ocrInput = new OcrInput();
// Set the target DPI to 300 for better OCR accuracy
ocrInput.TargetDPI = 300;

ocrInput.LoadImage(@"images\image.png");

// Perform OCR on the image with the specified DPI
var ocrResult = ocrTesseract.Read(ocrInput);
// Display the text extracted from the image
Console.WriteLine(ocrResult.Text);
// Display the confidence level of the OCR result
Console.WriteLine(ocrResult.Confidence);

What Results Can I Expect with Upscaled DPI?

Debug console showing OCR results: extracted text with 85% confidence score after DPI optimization

The output shows IronOCR achieves an 85% confidence score. Despite significant noise and the source image's low initial DPI, the result is accurate, demonstrating the effectiveness of the upscaling feature. For applications requiring even higher accuracy, consider implementing progress tracking to monitor confidence levels in real-time and adjust settings dynamically.

IronOCR includes built-in capabilities that automatically enhance low-resolution images by upscaling them within a single library. This approach eliminates the need for external image processing tools, streamlining your workflow and reducing dependencies. For developers getting started with IronOCR on Windows, this feature works immediately without additional configuration.

How Does DPI Setting Impact OCR Accuracy?

To illustrate the difference, here's the result of processing the same low-resolution image without setting the TargetDPI property. This comparison demonstrates why proper DPI configuration is crucial for reliable text extraction.

Finding the correct DPI requires balance. High DPI provides more accuracy but slower processing; low DPI is faster but less reliable. When in doubt, let IronTesseract's automatic preprocessing determine optimal settings. You can disable automatic upscaling by setting the TargetDPI property to 0. For specialized applications, explore our guide on Tesseract image DPI optimization.

What Happens Without DPI Upscaling?

Debug console showing poor OCR results: garbled text with 79% confidence, demonstrating low DPI extraction quality

Without upscaling, the confidence score drops to 79%, and the extracted text is significantly less accurate. This comparison highlights how setting a TargetDPI improves OCR results on low-quality images. The difference becomes more pronounced when dealing with complex documents containing tables, forms, or multi-column layouts.

How Do I Set DPI for PDF Documents?

When processing a PDF, IronOCR upscales the entire document to the target DPI, not just the images within it. This comprehensive approach ensures consistent quality throughout the document, which is important for PDF OCR text extraction in business applications. For advanced PDF processing, such as working with searchable PDFs, proper DPI configuration becomes even more critical.

While higher DPI often leads to better OCR results, the optimal setting varies between PDFs. If you're unsure which value to use, leave the DPI at its default setting and allow IronOCR to determine the best configuration automatically. The library's algorithms analyze document characteristics such as font size, image quality, and content density to select appropriate preprocessing parameters.

// Example: Processing a PDF with custom DPI settings
using IronOcr;

var ocrTesseract = new IronTesseract();

using var ocrInput = new OcrInput();

// Configure DPI specifically for PDF processing
ocrInput.TargetDPI = 250; // Lower DPI often works well for PDFs

// Load a multi-page PDF document
ocrInput.LoadPdf(@"documents\scanned-report.pdf");

// Optional: Process only specific pages
// ocrInput.LoadPdf(@"documents\scanned-report.pdf", PageSelection: new int[] {1, 3, 5});

// Apply additional filters if needed
ocrInput.DeNoise(); // Remove digital noise
ocrInput.Sharpen(); // Enhance text edges

// Perform OCR with confidence tracking
var ocrResult = ocrTesseract.Read(ocrInput);

// Process results page by page
foreach (var page in ocrResult.Pages)
{
    Console.WriteLine($"Page {page.PageNumber}: {page.Confidence}% confidence");
    Console.WriteLine(page.Text);
}
Warning: The maximum value for TargetDPI is 32,766. Setting a DPI higher than this limit will cause an exception. This happens because the resulting image dimensions would exceed Tesseract's maximum supported size of 32,767 x 32,767 pixels. If the limit is exceeded, you will receive the following error message: 'TargetDPI is too high and would result in an image too large ({new_width} x {new_height}) for Tesseract. The maximum image size for Tesseract is 32767 x 32767'

For enterprise applications processing large volumes of documents, consider implementing a dynamic DPI adjustment strategy. Start with a moderate setting (300 DPI) and adjust based on confidence scores. This approach balances processing speed with accuracy, ensuring optimal performance across diverse document types. Combining DPI optimization with other preprocessing techniques can yield better results for challenging documents.

When working with specific document types, DPI requirements may vary. For instance, reading license plates typically requires higher DPI settings due to small character size and potential image distortion from camera angles. Similarly, processing MICR cheques benefits from specific DPI configurations to accurately capture specialized MICR font characters.

For developers integrating OCR into web applications or cloud services, understanding DPI optimization becomes crucial for managing processing times and server resources. The ability to fine-tune DPI settings allows you to optimize the balance between accuracy and performance based on your specific application requirements and infrastructure constraints.

Frequently Asked Questions

What is DPI, and why does it matter for OCR?

DPI, or Dots Per Inch, measures the detail in scanned documents or digital images. Higher DPI settings provide more detail, which is crucial for accurate OCR. IronOCR uses DPI settings to improve text recognition, especially on low-resolution images.

How does IronOCR handle low-resolution images?

IronOCR employs the `TargetDPI` property to upscale low-resolution images, enhancing OCR accuracy. Its image preprocessing capabilities automatically detect and address image quality issues to improve text recognition.

What is the optimal DPI setting for OCR with IronOCR?

The optimal DPI setting for OCR with IronOCR typically ranges between 250 and 400 DPI, depending on the image quality and use case. IronOCR's `TargetDPI` property can be adjusted to achieve the best results for different document types.

Can IronOCR process PDF documents with DPI optimization?

Yes, IronOCR can process PDF documents and upscale them to the `TargetDPI` setting, ensuring consistent text extraction quality throughout the document. This approach is crucial for reliable PDF OCR in business and enterprise applications.

How does DPI setting impact OCR performance?

A higher DPI setting may result in better OCR accuracy, but it can also slow down processing. Conversely, a lower DPI setting may be faster but less accurate. IronOCR balances DPI settings to optimize both performance and accuracy.

What happens if the `TargetDPI` is set too high?

Setting the `TargetDPI` too high can cause an exception because it may create an image size that exceeds Tesseract's maximum supported dimensions of 32,767 x 32,767 pixels. IronOCR will notify you if this limit is exceeded.

Can IronOCR automatically adjust DPI settings?

Yes, IronOCR can automatically determine the optimal DPI settings by analyzing document characteristics such as font size and image quality, ensuring the best configuration without manual input.

How can I set the DPI for an image using IronOCR?

To set the DPI for an image using IronOCR, configure the `TargetDPI` property in the `OcrInput` class. This helps improve OCR accuracy by upscaling the image resolution to the desired DPI.

What results can I expect after DPI upscaling with IronOCR?

After DPI upscaling with IronOCR, you can expect improved text recognition and a higher confidence score. For example, an OCR confidence score can rise from 79% to 85%, demonstrating enhanced accuracy on challenging images.

How does IronOCR maintain performance while adjusting DPI?

IronOCR uses sophisticated algorithms to balance DPI settings and image preprocessing tasks, ensuring that both accuracy and processing speed are optimized. This capability is crucial for managing large volumes of documents efficiently.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...
Read More

Ready to Get Started?

Nuget Downloads 6,236,385Version:2026.9just released

Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package IronOcr
nuget.org/packages/IronOcr/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronOCR"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

or download Windows Installer here.

  1. Download and unzip IronOCR to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronOCR.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required