This commit is contained in:
38
docs/snippets/java/ocr/ocr_elements.md
Normal file
38
docs/snippets/java/ocr/ocr_elements.md
Normal file
@@ -0,0 +1,38 @@
|
||||
```java title="Java"
|
||||
import dev.kreuzberg.Kreuzberg;
|
||||
import dev.kreuzberg.ExtractionResult;
|
||||
import dev.kreuzberg.KreuzbergException;
|
||||
import dev.kreuzberg.ExtractionConfig;
|
||||
import dev.kreuzberg.OcrConfig;
|
||||
import dev.kreuzberg.types.OcrElement;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ExtractionConfig config = ExtractionConfig.builder()
|
||||
.ocr(OcrConfig.builder()
|
||||
.backend("paddle-ocr")
|
||||
.language("en")
|
||||
.build())
|
||||
.build();
|
||||
|
||||
ExtractionResult result = Kreuzberg.extractFile("scanned.pdf", config);
|
||||
|
||||
if (result.getOcrElements() != null) {
|
||||
for (OcrElement element : result.getOcrElements()) {
|
||||
System.out.printf("Text: %s%n", element.getText());
|
||||
System.out.printf("Confidence: %.2f%n", element.getConfidence().getRecognition());
|
||||
System.out.printf("Geometry: %s%n", element.getGeometry());
|
||||
if (element.getRotation() != null) {
|
||||
System.out.printf("Rotation: %.1f°%n", element.getRotation().getAngle());
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
} catch (IOException | KreuzbergException e) {
|
||||
System.err.println("Extraction failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user