在 IronOCR 中减小 PDF 文件大小

This article was translated from English: Does it need improvement?
Translated
View the article in English

如何在IronOCR中减小输出PDF的文件大小?

IronOCR 会自动提升检测到的低质量输入的清晰度。(低于 150DPI)确保读取结果的准确性。

如果检测到DPI低于150,则TargetDPI(默认 225DPI)定义PDF渲染的DPI——这与手动设置TargetDPI = 225相同。

要减小输出文件的大小,您可以设置较低的TargetDPI,这将创建更小的PDF文件,但过低可能会影响OCR的性能。 一切都在平衡中。

建议的值为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
VB   C#

要禁用自动放大,请使用 TargetDPI = 0。 这将忽略TargetDPI值,输入文件将按原样读取。

有关更多信息,请参阅API:https://ironsoftware.com/csharp/ocr/object-reference/api/IronOcr.OcrInput.html?q=targetdpi#IronOcr_OcrInput_TargetDPI