Reduce PDF File Size in IronOCR

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

如何在 IronOCR 中减小输出 PDF 的文件大小? IronOCR 会自动提升被检测为低质量(低于 150DPI)的输入,以确保读取结果的准确性。 如果检测到 DPI 低于 150,TargetDPI(默认值 225DPI)将定义渲染 PDF 的 DPI。 这等同于手动设置 `TargetDPI = 225`。 为减小输出文件大小,您可以设置较低的 `TargetDPI` 值,这样创建的 PDF 将更小。 但是,如果设置过低,可能会影响 OCR 性能,因此必须保持平衡。 建议值为 96、72、48。 ```csharp // 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 } ``` 要禁用自动缩放功能,请使用 `TargetDPI = 0`。 这将使 IronOCR 按原样读取输入文件,忽略 TargetDPI 值。 有关详细信息,请参阅 API:[IronOCR API Reference](https://ironsoftware.com/csharp/ocr/object-reference/api/IronOcr.OcrInput.html?q=targetdpi#IronOcr_OcrInput_TargetDPI)

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 5,044,537 | 版本: 2025.11 刚刚发布