Files
fil/docs/snippets/csharp/ocr/cloud_ocr_backend.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

1.7 KiB

using Kreuzberg;
using System.Collections.Generic;

public class CloudOcrBackend : IOcrBackend
{
    private string _apiKey;

    public string Name => "cloud-ocr";
    public string Version => "1.0.0";

    public CloudOcrBackend(string apiKey)
    {
        _apiKey = apiKey;
    }

    public void Initialize()
    {
    }

    public void Shutdown()
    {
    }

    public ExtractionResult ProcessImage(byte[] imageBytes, OcrConfig config)
    {
        // Call cloud OCR API with imageBytes and config.Language
        // Return ExtractionResult with extracted text
        throw new NotImplementedException();
    }

    public ExtractionResult ProcessImageFile(string path, OcrConfig config)
    {
        var imageBytes = File.ReadAllBytes(path);
        return ProcessImage(imageBytes, config);
    }

    public bool SupportsLanguage(string language)
    {
        return SupportedLanguages().Contains(language);
    }

    public OcrBackendType BackendType()
    {
        return OcrBackendType.Cloud;
    }

    public List<string> SupportedLanguages()
    {
        return new List<string> { "eng", "deu", "fra" };
    }

    public bool SupportsTableDetection()
    {
        return false;
    }

    public bool SupportsDocumentProcessing()
    {
        return false;
    }

    public ExtractionResult ProcessDocument(string path, OcrConfig config)
    {
        throw new NotSupportedException("Document processing not supported by CloudOcrBackend");
    }
}

class Program
{
    static void Main()
    {
        // Register the backend
        var backend = new CloudOcrBackend(apiKey: "your-api-key");
        OcrBackendBridge.Register(backend);
    }
}