This commit is contained in:
31
docs/snippets/kotlin/ocr/ocr_elements.md
Normal file
31
docs/snippets/kotlin/ocr/ocr_elements.md
Normal file
@@ -0,0 +1,31 @@
|
||||
```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()
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user