Reducir el tamaño de archivo PDF en IronOCR

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

¿Cómo puedo reducir el tamaño del archivo PDF de salida en IronOCR?

IronOCR aumentará automáticamente la calidad de las entradas detectadas como de baja calidad (menos de 150DPI) para garantizar resultados de lectura precisos.

Si se detecta un DPI inferior a 150, TargetDPI (por defecto 225DPI) define el DPI al que se renderiza un PDF. Esto es lo mismo que establecer manualmente TargetDPI = 225.

Para reducir el tamaño del archivo de salida, puede establecer un TargetDPI más bajo, lo que creará PDFs más pequeños. Sin embargo, establecerlo demasiado bajo puede afectar el rendimiento del OCR, por lo que es esencial mantener un equilibrio.

Los valores sugeridos son 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

Para desactivar el aumento de calidad automático, use TargetDPI = 0. Esto hará que IronOCR lea el archivo de entrada tal cual, ignorando el valor de TargetDPI.

Vea la API para más información: Referencia de la API de IronOCR

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 5,167,857 | Version: 2025.11 recién lanzado