Reduce PDF File Size in IronOCR

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

Wie reduziere ich die Dateigröße des Ausgabe-PDFs in IronOCR?

IronOCR wird automatisch Eingaben hochskalieren, die als minderwertig (unter 150DPI) erkannt werden, um genaue Leseergebnisse zu gewährleisten.

Wird ein DPI unter 150 erkannt, definiert TargetDPI (standardmäßig 225DPI) die DPI, bei denen ein PDF gerendert wird. Dies ist das gleiche wie manuelles Setzen von TargetDPI = 225.

Um die Dateigröße der Ausgabe zu reduzieren, können Sie einen niedrigeren TargetDPI einstellen, was kleinere PDFs erzeugen wird. Allerdings kann eine zu niedrige Einstellung die OCR-Leistung beeinträchtigen, daher ist es wichtig, ein Gleichgewicht zu halten.

Empfohlene Werte sind 96, 72, 48.

// Example of reducing PDF output file size by lowering the DPI

// Example 1: Reducing DPI to 96
using IronOcr;  // Import IronOCR namespace

var Ocr = new IronTesseract(); // Initialize IronTesseract for OCR operations

using (var Input = new OcrInput()) // Create OCR input object
{
    Input.TargetDPI = 96;    // Set the desired DPI; 96 is used for smaller output size
    Input.AddPdf("example.pdf", "password"); // Add input PDF (with optional password)

    var Result = Ocr.Read(Input); // Perform OCR on the input
    Console.WriteLine(Result.Text); // Output recognized text to the console
}

// Example 2: Another way to set DPI
var ocr = new IronTesseract();

using (var ocrInput = new OcrInput()) // Create a new OCR input object
{
    ocrInput.AddPdf("img/Input.pdf", 72); // Add PDF with the specified DPI of 72
    var ocrResult = ocr.Read(ocrInput); // Read and process the PDF

    ocrResult.SaveAsSearchablePdf(@"Output.pdf"); // Save result to a searchable PDF
}
// Example of reducing PDF output file size by lowering the DPI

// Example 1: Reducing DPI to 96
using IronOcr;  // Import IronOCR namespace

var Ocr = new IronTesseract(); // Initialize IronTesseract for OCR operations

using (var Input = new OcrInput()) // Create OCR input object
{
    Input.TargetDPI = 96;    // Set the desired DPI; 96 is used for smaller output size
    Input.AddPdf("example.pdf", "password"); // Add input PDF (with optional password)

    var Result = Ocr.Read(Input); // Perform OCR on the input
    Console.WriteLine(Result.Text); // Output recognized text to the console
}

// Example 2: Another way to set DPI
var ocr = new IronTesseract();

using (var ocrInput = new OcrInput()) // Create a new OCR input object
{
    ocrInput.AddPdf("img/Input.pdf", 72); // Add PDF with the specified DPI of 72
    var ocrResult = ocr.Read(ocrInput); // Read and process the PDF

    ocrResult.SaveAsSearchablePdf(@"Output.pdf"); // Save result to a searchable PDF
}
' Example of reducing PDF output file size by lowering the DPI

' Example 1: Reducing DPI to 96
Imports IronOcr ' Import IronOCR namespace

Private Ocr = New IronTesseract() ' Initialize IronTesseract for OCR operations

Using Input = New OcrInput() ' Create OCR input object
	Input.TargetDPI = 96 ' Set the desired DPI; 96 is used for smaller output size
	Input.AddPdf("example.pdf", "password") ' Add input PDF (with optional password)

	Dim Result = Ocr.Read(Input) ' Perform OCR on the input
	Console.WriteLine(Result.Text) ' Output recognized text to the console
End Using

' Example 2: Another way to set DPI
Dim ocr = New IronTesseract()

Using ocrInput As New OcrInput() ' Create a new OCR input object
	ocrInput.AddPdf("img/Input.pdf", 72) ' Add PDF with the specified DPI of 72
	Dim ocrResult = ocr.Read(ocrInput) ' Read and process the PDF

	ocrResult.SaveAsSearchablePdf("Output.pdf") ' Save result to a searchable PDF
End Using
$vbLabelText   $csharpLabel

Um das automatische Hochskalieren zu deaktivieren, verwenden Sie TargetDPI = 0. Dies wird IronOCR dazu bringen, die Eingabedatei unverändert zu lesen, wobei der TargetDPI-Wert ignoriert wird.

Siehe die API für mehr Informationen: IronOCR API Referenz

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Nuget Downloads 5,044,537 | Version: 2025.11 gerade veröffentlicht