IronOCRでPDFファイルサイズを縮小する

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

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
$vbLabelText   $csharpLabel

自動アップスケーリングを無効にするには、 TargetDPI = 0を使用します。 これにより、IronOCR は TargetDPI 値を無視して入力ファイルをそのまま読み取ります。

詳細については、API を参照してください: IronOCR API リファレンス

カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 5,167,857 | Version: 2025.11 リリース