Reduce PDF File Size in IronOCR
How do I reduce the file size of the output PDF in IronOCR?
IronOCR will automatically upscale inputs that are detected as low quality (below 150DPI) to ensure accurate read results.
If DPI below 150 is detected, TargetDPI (default 225DPI) defines the DPI that a PDF is rendered at - this is the same as manually setting TargetDPI = 225.
To reduce output file size you can set a lower TargetDPI, which will create smaller PDFs, but going too low may affect OCR performance. Everything in balance.
Suggested values are 96, 72, 48
// how to reduce and usage by by reducing DPI
//Example 1
using IronOcr;
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
Input.TargetDPI = 96; // DPI of output, default is 225
Input.AddPdf("example.pdf", "password");
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
//Example 2
var ocr = new IronTesseract();
using (var ocrInput = new OcrInput())
{
ocrInput.AddPdf("img/Input.pdf", 72); //TargetDPI
var ocrResult = ocr.Read(ocrInput);
ocrResult.SaveAsSearchablePdf(@"Output.pdf");
}
// how to reduce and usage by by reducing DPI
//Example 1
using IronOcr;
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
Input.TargetDPI = 96; // DPI of output, default is 225
Input.AddPdf("example.pdf", "password");
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
//Example 2
var ocr = new IronTesseract();
using (var ocrInput = new OcrInput())
{
ocrInput.AddPdf("img/Input.pdf", 72); //TargetDPI
var ocrResult = ocr.Read(ocrInput);
ocrResult.SaveAsSearchablePdf(@"Output.pdf");
}
' how to reduce and usage by by reducing DPI
'Example 1
Imports IronOcr
Private Ocr = New IronTesseract()
Using Input = New OcrInput()
Input.TargetDPI = 96 ' DPI of output, default is 225
Input.AddPdf("example.pdf", "password")
Dim Result = Ocr.Read(Input)
Console.WriteLine(Result.Text)
End Using
'Example 2
Dim ocr = New IronTesseract()
Using ocrInput As New OcrInput()
ocrInput.AddPdf("img/Input.pdf", 72) 'TargetDPI
Dim ocrResult = ocr.Read(ocrInput)
ocrResult.SaveAsSearchablePdf("Output.pdf")
End Using
To disable automatic upscaling, please use TargetDPI = 0
. This will ignore the TargetDPI value and the input file will be read as-in.
See the API for more information: https://ironsoftware.com/csharp/ocr/object-reference/api/IronOcr.OcrInput.html?q=targetdpi#IronOcr_OcrInput_TargetDPI