PDF-Dateigröße in IronOCR reduzieren
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 dasselbe wie die manuelle Einstellung von TargetDPI = 225.
Um die Dateigröße zu reduzieren, können Sie einen niedrigeren TargetDPI festlegen, wodurch kleinere PDFs erstellt werden. 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.LoadPdf("example.pdf", Password: "password"); // Load 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.TargetDPI = 72; // Set render DPI to 72
ocrInput.LoadPdf("img/Input.pdf"); // Load the PDF
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
Dim 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.LoadPdf("example.pdf", Password:="password") ' Load 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 = New OcrInput() ' Create a new OCR input object
ocrInput.TargetDPI = 72 ' Set render DPI to 72
ocrInput.LoadPdf("img/Input.pdf") ' Load the PDF
Dim ocrResult = ocr.Read(ocrInput) ' Read and process the PDF
ocrResult.SaveAsSearchablePdf("Output.pdf") ' Save result to a searchable PDF
End Using' Example of reducing PDF output file size by lowering the DPI
' Example 1: Reducing DPI to 96
Imports IronOcr ' Import IronOCR namespace
Dim 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.LoadPdf("example.pdf", Password:="password") ' Load 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 = New OcrInput() ' Create a new OCR input object
ocrInput.TargetDPI = 72 ' Set render DPI to 72
ocrInput.LoadPdf("img/Input.pdf") ' Load the PDF
Dim ocrResult = ocr.Read(ocrInput) ' Read and process the PDF
ocrResult.SaveAsSearchablePdf("Output.pdf") ' Save result to a searchable PDF
End UsingUm 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 weitere Informationen: IronOCR API Referenz
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 Handbücher.