IronOCRでPDFファイルサイズを縮小する
IronOCR で出力 PDF のファイル サイズを縮小するにはどうすればよいですか?
IronOCR は、低品質 (150DPI 未満) として検出された入力を自動的に拡大し、正確な読み取り結果を保証します。
150 未満の DPI が検出された場合、TargetDPI (デフォルト 225DPI) によって PDF がレンダリングされる DPI が定義されます。 これは、手動でTargetDPI = 225を設定するのと同じです。
出力ファイルサイズを削減するには、より低いTargetDPIを設定することができ、これにより小さいPDFが生成されます。 ただし、設定値が低すぎると OCR のパフォーマンスに影響する可能性があるため、バランスを保つことが重要です。
推奨値は 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自動アップスケーリングを無効にするには、 TargetDPI = 0を使用します。 これにより、IronOCR は TargetDPI 値を無視して入力ファイルをそのまま読み取ります。
詳細については、API を参照してください: IronOCR API リファレンス






