在 IronOCR 中减少 PDF 文件大小
This article was translated from English: Does it need improvement?
TranslatedView the article in English
如何减小 IronOCR 输出 PDF 的文件大小?
IronOCR 会自动将检测到的低质量(低于 150DPI)的输入图像放大,以确保准确的读取结果。
如果检测到 DPI 低于 150,则 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
}$vbLabelText $csharpLabel
要禁用自动放大,请使用TargetDPI = 0 。 这将使 IronOCR 按原样读取输入文件,忽略 TargetDPI 值。
更多信息请参阅 API: IronOCR API 参考
准备开始了吗?
Nuget 下载 5,299,091 | 版本: 2025.12 刚刚发布






