How to Set DPI in OCR Using C#
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.
Get started making PDFs with NuGet now:
Install IronOCR with NuGet Package Manager
Copy and run this code snippet.
var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrInput { TargetDPI = 300 }.LoadImage("low-res.png"));Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download a C# library to set the DPI settings for OCR
- Instantiate a new
OcrInput - Set the
TargetDPIto suit your needs - Load the desired Image in
- Read and extract data from the image using
Read
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".

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.
:path=/static-assets/ocr/content-code-examples/how-to/dpi-setting.csusing 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);IRON VB CONVERTER ERROR developers@ironsoftware.comWhat Results Can I Expect with Upscaled DPI?

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. This accuracy level surpasses traditional OCR solutions that struggle with low-quality inputs. 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?

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);
}// 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);
}IRON VB CONVERTER ERROR developers@ironsoftware.comTargetDPI 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 accuracy?
DPI (Dots Per Inch) measures image quality and determines the level of detail in scanned documents. For OCR accuracy, higher DPI means clearer character definitions. IronOCR can handle images with resolutions as low as 225 DPI while maintaining high accuracy, thanks to its advanced image preprocessing capabilities.
How can I improve OCR results on low-resolution images?
Set the TargetDPI property in IronOCR's OcrInput class to upscale low-resolution images. For example, setting TargetDPI to 300 can significantly improve text recognition on blurry or pixelated documents, even those with resolutions as low as 100 DPI.
What's the quickest way to set DPI for OCR in C#?
You can configure DPI in one line of code using IronOCR: var result = new IronOcr.IronTesseract().Read(new IronOcr.OcrInput { TargetDPI = 300 }.LoadImage("low-res.png")). This automatically upscales your image for better text clarity and recognition.
Can OCR work effectively on scanned documents with low resolution?
Yes, IronOCR is specifically designed to handle low-resolution scanned documents effectively. It achieves high accuracy on scans with resolutions as low as 225 DPI and includes automatic image preprocessing features that detect and compensate for various quality issues.
What are the basic steps to implement DPI settings for OCR?
The process involves five steps: 1) Download IronOCR library, 2) Instantiate a new OcrInput object, 3) Set the TargetDPI property to your desired value, 4) Load your image using LoadImage method, and 5) Extract text using the Read method.
Why do default scan settings often result in poor OCR performance?
Default or quick scan settings typically produce low-resolution files to save time and storage space. This results in blurry or pixelated text where fine details are lost, making it difficult for OCR engines to accurately identify character shapes. IronOCR's TargetDPI feature helps overcome this limitation.






