This commit is contained in:
22
docs/snippets/swift/ocr/cloud_ocr_backend.md
Normal file
22
docs/snippets/swift/ocr/cloud_ocr_backend.md
Normal file
@@ -0,0 +1,22 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
// Custom/cloud OCR backends are registered via the Rust plugin system.
|
||||
// From Swift, select a registered custom backend by name through the
|
||||
// JSON configuration:
|
||||
let configJson = """
|
||||
{
|
||||
"ocr": {
|
||||
"backend": "custom",
|
||||
"language": "eng"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("scanned.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
18
docs/snippets/swift/ocr/image_extraction.md
Normal file
18
docs/snippets/swift/ocr/image_extraction.md
Normal file
@@ -0,0 +1,18 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"images": {
|
||||
"extract_images": true
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("document.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
20
docs/snippets/swift/ocr/image_preprocessing.md
Normal file
20
docs/snippets/swift/ocr/image_preprocessing.md
Normal file
@@ -0,0 +1,20 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"images": {
|
||||
"extract_images": true,
|
||||
"target_dpi": 300,
|
||||
"max_image_dimension": 2000
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("document.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
19
docs/snippets/swift/ocr/ocr_easyocr.md
Normal file
19
docs/snippets/swift/ocr/ocr_easyocr.md
Normal file
@@ -0,0 +1,19 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"ocr": {
|
||||
"backend": "easyocr",
|
||||
"language": "en"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("document.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
26
docs/snippets/swift/ocr/ocr_elements.md
Normal file
26
docs/snippets/swift/ocr/ocr_elements.md
Normal file
@@ -0,0 +1,26 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"ocr": {
|
||||
"backend": "paddleocr",
|
||||
"language": "en",
|
||||
"element_config": {
|
||||
"include_elements": true
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("scanned.pdf", nil, config)
|
||||
|
||||
if let elements = result.ocr_elements() {
|
||||
for element in elements {
|
||||
print("Text: \(element.text().toString())")
|
||||
}
|
||||
}
|
||||
```
|
||||
19
docs/snippets/swift/ocr/ocr_extraction.md
Normal file
19
docs/snippets/swift/ocr/ocr_extraction.md
Normal file
@@ -0,0 +1,19 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"ocr": {
|
||||
"backend": "tesseract",
|
||||
"language": "eng"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("scanned.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
20
docs/snippets/swift/ocr/ocr_force_all_pages.md
Normal file
20
docs/snippets/swift/ocr/ocr_force_all_pages.md
Normal file
@@ -0,0 +1,20 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"force_ocr": true,
|
||||
"ocr": {
|
||||
"backend": "tesseract",
|
||||
"language": "eng"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("document.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
19
docs/snippets/swift/ocr/ocr_multi_language.md
Normal file
19
docs/snippets/swift/ocr/ocr_multi_language.md
Normal file
@@ -0,0 +1,19 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"ocr": {
|
||||
"backend": "tesseract",
|
||||
"language": "eng+deu+fra"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("multilingual.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
19
docs/snippets/swift/ocr/ocr_paddleocr.md
Normal file
19
docs/snippets/swift/ocr/ocr_paddleocr.md
Normal file
@@ -0,0 +1,19 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"ocr": {
|
||||
"backend": "paddleocr",
|
||||
"language": "en"
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("document.pdf", nil, config)
|
||||
|
||||
print(result.content().toString())
|
||||
```
|
||||
Reference in New Issue
Block a user