Zmniejsz rozmiar pliku PDF w IronOCR
Jak zmniejszyć rozmiar pliku wyjściowego PDF w IronOCR?
IronOCR automatycznie przeskaluje wejścia, które są wykrywane jako niskiej jakości (poniżej 150DPI), aby zapewnić dokładne wyniki odczytu.
Jeśli zostanie wykryte DPI poniżej 150, TargetDPI (domyślnie 225DPI) definiuje DPI, przy którym PDF jest renderowany. To jest to samo, co reczne ustawienie TargetDPI = 225.
Aby zmniejszyć rozmiar pliku wyjściowego, można ustawić niższy TargetDPI, co stworzy mniejsze pliki PDF. Jednak zbyt niskie ustawienie może wpłynąć na wydajność OCR, dlatego ważne jest utrzymanie równowagi.
Sugerowane wartości to 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.LoadPdf("example.pdf", Password: "password"); // Load 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.TargetDPI = 72; // Set render DPI to 72
ocrInput.LoadPdf("img/Input.pdf"); // Load the PDF
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
Dim 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.LoadPdf("example.pdf", Password:="password") ' Load 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 = New OcrInput() ' Create a new OCR input object
ocrInput.TargetDPI = 72 ' Set render DPI to 72
ocrInput.LoadPdf("img/Input.pdf") ' Load the PDF
Dim ocrResult = ocr.Read(ocrInput) ' Read and process the PDF
ocrResult.SaveAsSearchablePdf("Output.pdf") ' Save result to a searchable PDF
End Using' Example of reducing PDF output file size by lowering the DPI
' Example 1: Reducing DPI to 96
Imports IronOcr ' Import IronOCR namespace
Dim 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.LoadPdf("example.pdf", Password:="password") ' Load 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 = New OcrInput() ' Create a new OCR input object
ocrInput.TargetDPI = 72 ' Set render DPI to 72
ocrInput.LoadPdf("img/Input.pdf") ' Load the PDF
Dim ocrResult = ocr.Read(ocrInput) ' Read and process the PDF
ocrResult.SaveAsSearchablePdf("Output.pdf") ' Save result to a searchable PDF
End UsingAby wylaczyc automatyczne przeskalowanie, uzyj TargetDPI = 0. To spowoduje, że IronOCR będzie odczytywał plik wejściowy tak, jak jest, ignorując wartość TargetDPI.
Zobacz API, aby uzyskać więcej informacji: Dokumentacja API IronOCR
Curtis Chau posiada tytuł licencjata z informatyki (Uniwersytet Carleton) i specjalizuje się w front-endowym rozwoju, z ekspertką w Node.js, TypeScript, JavaScript i React. Pasjonuje się tworzeniem intuicyjnych i estetycznie przyjemnych interfejsów użytkownika, Curtis cieszy się pracą z nowoczesnymi frameworkami i tworzeniem dobrze zorganizowanych, atrakcyjnych wizualnie podręczników.