Files
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
..
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00
2026-06-01 23:40:55 +02:00

Zig

Extract text, tables, images, and metadata from 90+ file formats and 300+ programming languages including PDF, Office documents, and images. Zig bindings consuming the C FFI surface via @cImport, idiomatic error sets, optional types, and slice-based memory management.

What This Package Provides

  • Document intelligence core — extract text, tables, images, metadata, entities, keywords, and code intelligence from one API.
  • Format coverage — PDF, Office, images, HTML/XML, email, archives, notebooks, citations, scientific formats, and plain text.
  • OCR choices — Tesseract, PaddleOCR, EasyOCR where supported, VLM OCR through liter-llm, and plugin hooks for custom backends.
  • Same engine as every binding — Rust, Python, Node.js, Go, Java, PHP, Ruby, .NET, Elixir, R, WASM, Kotlin Android, Swift, Dart, Zig, and C FFI share the same Rust implementation.
  • Zig package — wrapper over the C FFI with explicit memory ownership.

Installation

Package Installation

Fetch the package and pin it in build.zig.zon:

zig fetch --save https://github.com/kreuzberg-dev/kreuzberg/archive/refs/tags/v5.0.0-rc.3.tar.gz

Then wire it into build.zig:

const kreuzberg_dep = b.dependency("kreuzberg", .{
    .target = target,
    .optimize = optimize,
});
exe.root_module.addImport("kreuzberg", kreuzberg_dep.module("kreuzberg"));

System Requirements

  • Zig 0.16.0+ required (minimum_zig_version declared in build.zig.zon)
  • Links the C FFI surface from kreuzberg-ffi; the build resolves the library via linkSystemLibrary against the consumer-provided search path
  • Optional: ONNX Runtime version 1.22.x for embeddings support
  • Optional: Tesseract OCR for OCR functionality

Quick Start

Basic Extraction

Extract text, metadata, and structure from any supported document format:

const std = @import("std");
const kreuzberg = @import("kreuzberg");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    const config_json = "{}";
    const result_json = try kreuzberg.extract_file_sync("document.pdf", null, config_json);
    defer std.heap.c_allocator.free(result_json);

    const owned = try allocator.dupe(u8, result_json);
    defer allocator.free(owned);

    const stdout = std.io.getStdOut().writer();
    try stdout.print("{s}\n", .{owned});
}

Common Use Cases

Extract with Custom Configuration

Most use cases benefit from configuration to control extraction behavior:

With OCR (for scanned documents):

const std = @import("std");
const kreuzberg = @import("kreuzberg");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    const config_json =
        \\{
        \\  "ocr": {
        \\    "backend": "tesseract",
        \\    "language": "eng"
        \\  }
        \\}
    ;

    const result_json = try kreuzberg.extract_file_sync("scanned.pdf", null, config_json);
    defer std.heap.c_allocator.free(result_json);

    const owned = try allocator.dupe(u8, result_json);
    defer allocator.free(owned);

    const stdout = std.io.getStdOut().writer();
    try stdout.print("{s}\n", .{owned});
}

Table Extraction

See Configuration Guide for table extraction options.

Processing Multiple Files

const std = @import("std");
const kreuzberg = @import("kreuzberg");

pub fn main() !void {
    // Batch items are passed as a JSON-encoded array across the FFI boundary.
    const items_json =
        \\[
        \\  {"path": "doc1.pdf", "config": null},
        \\  {"path": "doc2.docx", "config": null},
        \\  {"path": "report.pdf", "config": null}
        \\]
    ;
    const config_json = "{}";

    const results_json = try kreuzberg.batch_extract_files_sync(items_json, config_json);
    defer std.heap.c_allocator.free(results_json);

    const stdout = std.io.getStdOut().writer();
    try stdout.print("{s}\n", .{results_json});
}

Async Processing

For non-blocking document processing:

const std = @import("std");
const kreuzberg = @import("kreuzberg");

// Note: the Zig binding is sync-only. There is no `extract_file` async variant —
// the FFI surface exposes blocking entry points that internally drive the global
// Tokio runtime. Use `extract_file_sync` from any thread.
pub fn main() !void {
    const config_json = "{}";
    const result_json = try kreuzberg.extract_file_sync("document.pdf", null, config_json);
    defer std.heap.c_allocator.free(result_json);

    const stdout = std.io.getStdOut().writer();
    try stdout.print("{s}\n", .{result_json});
}

Next Steps

Features

Supported File Formats (90+)

90+ file formats across 8 major categories with intelligent format detection and comprehensive metadata extraction.

Office Documents

Category Formats Capabilities
Word Processing .docx, .docm, .dotx, .dotm, .dot, .odt Full text, tables, images, metadata, styles
Spreadsheets .xlsx, .xlsm, .xlsb, .xls, .xla, .xlam, .xltm, .xltx, .xlt, .ods Sheet data, formulas, cell metadata, charts
Presentations .pptx, .pptm, .ppsx, .potx, .potm, .pot, .ppt Slides, speaker notes, images, metadata
PDF .pdf Text, tables, images, metadata, OCR support
eBooks .epub, .fb2 Chapters, metadata, embedded resources
Database .dbf Table data extraction, field type support
Hangul .hwp, .hwpx Korean document format, text extraction

Images (OCR-Enabled)

Category Formats Features
Raster .png, .jpg, .jpeg, .gif, .webp, .bmp, .tiff, .tif OCR, table detection, EXIF metadata, dimensions, color space
Advanced .jp2, .jpx, .jpm, .mj2, .jbig2, .jb2, .pnm, .pbm, .pgm, .ppm OCR via hayro-jpeg2000 (pure Rust decoder), JBIG2 support, table detection, format-specific metadata
Vector .svg DOM parsing, embedded text, graphics metadata

Web & Data

Category Formats Features
Markup .html, .htm, .xhtml, .xml, .svg DOM parsing, metadata (Open Graph, Twitter Card), link extraction
Structured Data .json, .yaml, .yml, .toml, .csv, .tsv Schema detection, nested structures, validation
Text & Markdown .txt, .md, .markdown, .djot, .rst, .org, .rtf CommonMark, GFM, Djot, reStructuredText, Org Mode

Email & Archives

Category Formats Features
Email .eml, .msg Headers, body (HTML/plain), attachments, threading
Archives .zip, .tar, .tgz, .gz, .7z File listing, nested archives, metadata

Academic & Scientific

Category Formats Features
Citations .bib, .biblatex, .ris, .nbib, .enw, .csl Structured parsing: RIS (structured), PubMed/MEDLINE, EndNote XML (structured), BibTeX, CSL JSON
Scientific .tex, .latex, .typst, .jats, .ipynb, .docbook LaTeX, Jupyter notebooks, PubMed JATS
Documentation .opml, .pod, .mdoc, .troff Technical documentation formats

Code Intelligence (300+ Languages)

Feature Description
Structure Extraction Functions, classes, methods, structs, interfaces, enums
Import/Export Analysis Module dependencies, re-exports, wildcard imports
Symbol Extraction Variables, constants, type aliases, properties
Docstring Parsing Google, NumPy, Sphinx, JSDoc, RustDoc, and 10+ formats
Diagnostics Parse errors with line/column positions
Syntax-Aware Chunking Split code by semantic boundaries, not arbitrary byte offsets

Powered by tree-sitter-language-packdocumentation.

Complete Format Reference

Key Capabilities

  • Text Extraction - Extract all text content with position and formatting information
  • Metadata Extraction - Retrieve document properties, creation date, author, etc.
  • Table Extraction - Parse tables with structure and cell content preservation
  • Image Extraction - Extract embedded images and render page previews
  • OCR Support - Integrate multiple OCR backends for scanned documents
  • Plugin System - Extensible post-processing for custom text transformation
  • Embeddings - Generate vector embeddings using ONNX Runtime models
  • Batch Processing - Efficiently process multiple documents in parallel
  • Memory Efficient - Stream large files without loading entirely into memory
  • Language Detection - Detect and support multiple languages in documents
  • Code Intelligence - Extract structure, imports, exports, symbols, and docstrings from 300+ programming languages via tree-sitter
  • Configuration - Fine-grained control over extraction behavior

Performance Characteristics

Format Speed Memory Notes
PDF (text) 10-100 MB/s ~50MB per doc Fastest extraction
Office docs 20-200 MB/s ~100MB per doc DOCX, XLSX, PPTX
Images (OCR) 1-5 MB/s Variable Depends on OCR backend
Archives 5-50 MB/s ~200MB per doc ZIP, TAR, etc.
Web formats 50-200 MB/s Streaming HTML, XML, JSON

OCR Support

Kreuzberg supports multiple OCR backends for extracting text from scanned documents and images:

  • Tesseract

  • Paddleocr

OCR Configuration Example

const std = @import("std");
const kreuzberg = @import("kreuzberg");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    const config_json =
        \\{
        \\  "ocr": {
        \\    "backend": "tesseract",
        \\    "language": "eng"
        \\  }
        \\}
    ;

    const result_json = try kreuzberg.extract_file_sync("scanned.pdf", null, config_json);
    defer std.heap.c_allocator.free(result_json);

    const owned = try allocator.dupe(u8, result_json);
    defer allocator.free(owned);

    const stdout = std.io.getStdOut().writer();
    try stdout.print("{s}\n", .{owned});
}

Plugin System

Kreuzberg supports extensible post-processing plugins for custom text transformation and filtering.

For detailed plugin documentation, visit Plugin System Guide.

Embeddings Support

Generate vector embeddings for extracted text using the built-in ONNX Runtime support. Requires ONNX Runtime installation.

Embeddings Guide

Batch Processing

Process multiple documents efficiently:

const std = @import("std");
const kreuzberg = @import("kreuzberg");

pub fn main() !void {
    // Batch items are passed as a JSON-encoded array across the FFI boundary.
    const items_json =
        \\[
        \\  {"path": "doc1.pdf", "config": null},
        \\  {"path": "doc2.docx", "config": null},
        \\  {"path": "report.pdf", "config": null}
        \\]
    ;
    const config_json = "{}";

    const results_json = try kreuzberg.batch_extract_files_sync(items_json, config_json);
    defer std.heap.c_allocator.free(results_json);

    const stdout = std.io.getStdOut().writer();
    try stdout.print("{s}\n", .{results_json});
}

Configuration

For advanced configuration options including language detection, table extraction, OCR settings, and more:

Configuration Guide

Documentation

Contributing

Contributions are welcome! See Contributing Guide.

Part of Kreuzberg.dev

  • Kreuzberg Cloud — managed extraction API with SDKs, dashboards, and observability.
  • kreuzcrawl — web crawling and scraping with HTML→Markdown and headless-Chrome fallback.
  • html-to-markdown — fast, lossless HTML→Markdown engine.
  • liter-llm — universal LLM API client with native bindings for 14 languages and 143 providers.
  • tree-sitter-language-pack — tree-sitter grammars and code-intelligence primitives.
  • alef — the polyglot binding generator that produces this README and all per-language bindings.
  • Discord — community, roadmap, announcements.

License

Elastic-2.0 License — see LICENSE for details.

Support