IronOCR'da PDF Dosya Boyutunu Azaltma
IronOCR'da çıktı PDF dosyasının boyutunu nasıl azaltabilirim?
IronOCR, doğru okuma sonuçları sağlamak için düşük kaliteli olarak algılanan (150DPI'nin altında) girdileri otomatik olarak büyütecektir.
150 DPI'nin altında algılanırsa, HedefDPI (varsayılan 225DPI), bir PDF'nin oluşturulacağı DPI'yi tanımlar. Bu, TargetDPI = 225'yi manuel olarak ayarlamakla aynıdır.
Çıktı dosyası boyutunu azaltmak için daha düşük bir TargetDPI ayarlayabilirsiniz, bu da daha küçük PDF'ler oluşturacaktır. Ancak, çok düşük ayarlamak OCR performansını etkileyebilir, bu yüzden bir denge sağlamanız önemlidir.
Önerilen değerler 96, 72, 48'dir.
// 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
Otomatik ölçeklendirmeyi devre dışı bırakmak için TargetDPI = 0 kullanın. Bu, IronOCR'un girdiyi olduğu gibi okumasını sağlayacak ve HedefDPI değerini görmezden gelecektir.
Daha fazla bilgi için API'ye bakın: IronOCR API Referansı

