Files
fil/docs/snippets/kotlin/ocr/ocr_elements.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

32 lines
872 B
Markdown

```kotlin title="Kotlin"
import dev.kreuzberg.*
import java.nio.file.Paths
import java.util.Optional
fun main() {
val elementConfig = OcrElementConfig.builder()
.withIncludeElements(true)
.build()
val ocr = OcrConfig.builder()
.withBackend("paddleocr")
.withLanguage("en")
.withElementConfig(Optional.of(elementConfig))
.build()
val config = ExtractionConfig.builder()
.withOcr(Optional.of(ocr))
.build()
val result = Kreuzberg.extractFileSync(Paths.get("scanned.pdf"), null, config)
result.ocrElements()?.forEach { element ->
println("Text: ${element.text()}")
println("Confidence: ${element.confidence().recognition()}")
println("Geometry: ${element.geometry()}")
element.rotation()?.let { println("Rotation: ${it}") }
println()
}
}
```