Skip to content

About

Tesseract OCR for flutter

Resources

Stars

105 stars

Watchers

4 watching

Forks

Repository files navigation

Tesseract OCR for Flutter

A Flutter plugin that provides Optical Character Recognition (OCR) capabilities using Tesseract (v4.x) and Apple Vision (iOS).

This plugin utilizes:

  • Android: Tesseract4Android
  • iOS: SwiftyTesseract (with support for v4.0.1 via custom CocoaPods) and Apple's Vision framework.
  • Web: Tesseract.js (v6.0.1 WebAssembly) using the app's bundled .traineddata assets.
  • macOS: Tesseract OCR through the same in-process Swift plugin as iOS (SwiftyTesseract + libtesseract) — no tesseract binary is installed on the machine.
  • Linux: System Tesseract OCR and Leptonica libraries via C++ CMake plugin.
  • Windows: Tesseract OCR and Leptonica libraries via C++ CMake plugin (vcpkg, MSYS2, or the UB-Mannheim installer).

🦒 Zuraffa Browser — Launch Offer

Zuraffa Browser — 10 Browsers. One window.

From the makers of this plugin: Zuraffa Browser — the multi-tasking browser for AI agents & humans — is live on the Mac App Store.

🎁 Launch offer: 6 months free with code ZURAFFA — no credit card, no subscription, no payment. Redeem in-app until Dec 1, 2026.

Download Zuraffa Browser →

Features

  • Perform OCR on images to extract text.
  • Support for multiple OCR engines: Tesseract (Android, iOS, macOS, Linux, Windows, and Web), Apple Vision (iOS only).
  • Configurable OCR options (language, engine mode, page segmentation mode, etc.) using OCRConfig.
  • Supports the latest Dart and Android SDKs.
  • Swift Package Manager (SPM) support for iOS and macOS (recommended): the plugin root carries a Package.swift that depends on SwiftyTesseract 4.0.1, and the Flutter build for both Apple platforms goes through the plugin's ios/ and macos/ podspecs, which compile that same Swift source
  • Linux support via system tesseract library
  • Windows support via a C++ plugin that links Tesseract and bundles its DLLs

Getting Started

1. Add Dependency

Add tesseract_ocr to your pubspec.yaml:

dependencies:
  tesseract_ocr: ^<latest_version> # Replace <latest_version> with the current version

Then run flutter pub get.

2. Add Trained Data (Required for Tesseract Engine)

For the Tesseract engine to work, you need to include language trained data files (.traineddata) and a configuration file (tessdata_config.json) in your Flutter app's assets.

  1. Create assets and assets/tessdata folders in the root of your Flutter project.

  2. Download Trained Data: Get the necessary .traineddata files for the languages you need from the Tesseract tessdata, tessdata_best, or tessdata_fast repositories. Place them inside your assets/tessdata folder. For English, you'll typically need eng.traineddata.

  3. Create tessdata_config.json: Create a file named tessdata_config.json directly inside your assets folder (not in assets/tessdata). This file should list all the .traineddata files present in your assets/tessdata folder.

    Example assets/tessdata_config.json:

    {
      "files": [
        "eng.traineddata",
        "fas.traineddata",
        "urd.traineddata"
        // Add all other .traineddata filenames here
      ]
    }
  4. Declare Assets in pubspec.yaml: Add your assets and assets/tessdata directories to the assets section of your pubspec.yaml:

    flutter:
      assets:
        - assets/tessdata_config.json
        - assets/tessdata/

    Run flutter pub get again.

The plugin will automatically copy these trained data files to the application's documents directory on the first run if they are not already present.

Note on Asset Loading Issues: If you encounter asset loading errors or "Data path must not be null!" errors, ensure your setup follows these exact requirements:

  1. Directory Structure:

    your_project/
    ├── assets/
    │   ├── tessdata/
    │   │   ├── eng.traineddata
    │   │   └── [other language files]
    │   └── tessdata_config.json
    └── pubspec.yaml
    
  2. pubspec.yaml assets section:

    flutter:
      assets:
        - assets/
        - assets/tessdata/
  3. tessdata_config.json content:

    {
      "files": ["eng.traineddata"]
    }

Troubleshooting:

  • Ensure .traineddata files are in assets/tessdata/ directory
  • Verify all language files listed in tessdata_config.json actually exist
  • Try adding individual file entries in pubspec.yaml if assets fail to load:
    assets:
      - assets/tessdata_config.json
      - assets/tessdata/eng.traineddata
  • A release build only carries the assets your pubspec.yaml declares. The plugin refuses to start recognition with an incomplete tessdata set instead of returning garbage — see the error codes below.

Load Trained Data From a Device Directory (No Asset Copy)

Bundling .traineddata as Flutter assets is not the only option. When the language packs are already on the device — downloaded at runtime, unpacked from a downloaded archive, or shared by another app — point recognition at that directory and the asset copy step is skipped entirely:

final config = OCRConfig(
  language: 'eng',
  engine: OCREngine.tesseract,
  tessDataPath: '/storage/emulated/0/Download/tesseract/tessdata',
);
final text = await TesseractOcr.extractText(imagePath, config: config);

The directory is read as-is, in either layout:

<your-directory>/eng.traineddata           # the files directly in it
<your-directory>/tessdata/eng.traineddata # or in a tessdata subdirectory

This is the flow for large language packs and download-on-demand: nothing is written to the app's documents directory, and the first recognition can start as soon as the download finishes.

On Android the engine reads its data from <datapath>/tessdata/<lang>.traineddata only, so the file-holding directory has to be named tessdata there: point tessDataPath at the directory that carries the tessdata subdirectory (as in the example above), or at a tessdata directory holding the files directly. A direct layout under any other name is refused with tessdata-path-invalid instead of an init failure inside the engine. iOS and macOS read the file-holding directory itself, so both layouts work as documented.

The directory is validated before the engine is asked to read it. A path that is missing, is not a directory, or does not carry every .traineddata the requested language needs raises a PlatformException with code tessdata-path-invalid naming the directory and the missing file(s) — see the error codes below.

tessDataPath applies to the Tesseract engine only: OCREngine.vision reads no .traineddata at all, so the override is ignored there.

Common Issues and Solutions

"Data path must not be null!" Error

This error typically occurs when:

  • The tessdata files are not properly loaded from assets
  • The tessdata_config.json file is missing or incorrectly formatted
  • Asset paths in pubspec.yaml are not correctly configured

Solution: Follow the exact directory structure and configuration shown above.

tessdata-path-invalid Error

A tessDataPath you passed does not name a tessdata directory the engine can read: it is missing, it is not a directory, it does not hold every .traineddata the requested language needs (eng.traineddata for 'eng', and both eng.traineddata and deu.traineddata for 'eng+deu'), or a needed .traineddata is empty (0 bytes — where a truncated download lands). On Android the file-holding directory also has to be named tessdata (see above). The message names the directory, the offending file(s), and both layouts it accepts.

Solution: download the missing .traineddata file(s) into that directory (the tessdata_fast set is the smallest), delete and re-download a 0-byte one, point tessDataPath at a directory the engine can read, or drop the override to fall back to the bundled assets/tessdata/ set.

tessdata-config-invalid / tessdata-asset-invalid Errors

extractText now refuses to run when the tessdata set it would hand to Tesseract is incomplete, instead of letting the engine initialize on an empty or partial directory and return garbage. Both are PlatformExceptions whose message names the offending asset and the pubspec.yaml declaration that carries it.

  • tessdata-config-invalid — assets/tessdata_config.json is not valid JSON, is not an object, does not carry a non-empty files array, or lists an entry that is not a flat .traineddata file name (a path such as sub/eng.traineddata, or an entry that is not a string, is a config mistake). It must be an object with a non-empty files array: {"files": ["eng.traineddata"]}.
  • tessdata-asset-invalid — assets/tessdata_config.json is not carried by the bundle, or a .traineddata listed in that config is not carried by the bundle, is empty, or differs from the file already on disk (missing, truncated, or replaced by another build) and cannot be rewritten.

Solution:

  1. Declare the config and every traineddata it lists under flutter: assets: in your app's pubspec.yaml — individually, if the directory form does not pick them up:

    assets:
      - assets/tessdata_config.json
      - assets/tessdata/eng.traineddata
  2. Run flutter clean && flutter pub get, then rebuild. Release builds only carry declared assets, so an install that predates a declaration keeps the old, empty tessdata directory — the copy is refreshed whenever the asset's contents differ from the file already on disk, so a same-size file from an older build is replaced too. Assets are read once per app run, so the copy check costs one read per declared file rather than one per extractText call.

"Unable to load asset" Error

This happens when Flutter cannot find the specified asset files.

Solution:

  1. Verify file names match exactly between tessdata_config.json and actual files
  2. Ensure proper asset declarations in pubspec.yaml
  3. Try running flutter clean and flutter pub get

Path Duplication Issues (M1 Macs)

Some users on M1 Macs may see paths like assets/tessdata/assets/tessdata/file.traineddata.

Solution: The plugin automatically handles this, but ensure you're using the latest version.

iOS Specific Setup (Swift Package Manager - Recommended)

Starting with version 0.5.2+, this plugin ships Swift Package Manager (SPM) support for iOS, which is the recommended approach going forward.

SPM Installation (Recommended)

The plugin root carries a Package.swift that targets iOS 11.0+ and depends on SwiftyTesseract 4.0.1+, so an app that consumes the plugin through Swift Package Manager adds the plugin root and gets the engine fetched and built for it — no additional configuration is required.

Requirements:

  • iOS 11.0 or later
  • Xcode 12.0 or later
  • Flutter 3.19.0 or later

A Flutter build (flutter build ios / flutter run) resolves the plugin through its ios/tesseract_ocr.podspec, which compiles the same shared Swift source and therefore still needs libtesseract.xcframework next to ios/libtesseract.podspec — see the legacy setup below for where the binary goes.

Legacy CocoaPods Setup (Deprecated)

⚠️ DEPRECATED: The CocoaPods setup is deprecated and will be removed in a future version. Please migrate to SPM.

For existing projects using CocoaPods, the legacy setup is still available but requires manual steps:

  1. Download libtesseract.xcframework: SwiftyTesseract 4.0.1 depends on libtesseract version 0.2.0, which is also not available on CocoaPods. You need to download the pre-built binary framework. Get libtesseract-0.2.0.xcframework.zip from the libtesseract GitHub Releases page.

  2. Extract and Place libtesseract.xcframework: Unzip the downloaded file. Place the resulting libtesseract.xcframework folder directly into the plugin's ios directory — the directory that contains libtesseract.podspec — not into your app's ios directory.

    The plugin's pod is consumed by :path from its own ios directory, and libtesseract.podspec resolves the xcframework relative to itself. So the binary must sit beside the podspec:

    .symlinks/plugins/tesseract_ocr/ios/
    ├── libtesseract.podspec          <-- The podspec that consumes it
    ├── libtesseract.xcframework      <-- Place the extracted folder here
    ├── SwiftyTesseract401.podspec
    └── tesseract_ocr.podspec
    

    Your app's own ios directory keeps only the usual Flutter files (Runner.xcodeproj, Runner.xcworkspace, Podfile) — the xcframework does not belong there.

  3. Configure Your App's Podfile: In your Flutter app's ios/Podfile, you need to reference the custom podspecs provided within the tesseract_ocr plugin: SwiftyTesseract401 by :podspec, libtesseract by :path. No EXCLUDED_ARCHS entry is needed — the arm64 Apple Silicon simulator slice builds on its own.

    Locate your target 'Runner' block and add the following lines:

    # In your main Flutter app's Podfile (e.g., your_flutter_app/ios/Podfile)
    
    # ... other Podfile content ...
    
    target 'Runner' do
      use_frameworks!
      use_modular_headers!
    
      # This line should already be here if you added the plugin via pubspec.yaml
      pod 'tesseract_ocr', :path => '../.symlinks/plugins/tesseract_ocr/'
    
      # Add the custom SwiftyTesseract401 and libtesseract pods
      # These paths are relative from YOUR app's ios directory to the plugin's ios directory
      # Adjust the '../../.symlinks/plugins/tesseract_ocr/ios' path if necessary
      pod 'SwiftyTesseract401', :podspec => '../../.symlinks/plugins/tesseract_ocr/ios/SwiftyTesseract401.podspec'
      pod 'libtesseract', :path => '../../.symlinks/plugins/tesseract_ocr/ios'
    
    
      # flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) # Keep this line
    
    end
    
    # ... other Podfile content (e.g., post_install hook) ...

    Note: The :path value ../../.symlinks/plugins/tesseract_ocr/ios is the standard path from your app's ios directory to a plugin's ios directory when using Flutter. If your project structure is different, you may need to adjust this path.

  4. Install Pods: Navigate to your ios directory in the terminal and run pod install:

    cd your_flutter_app/ios
    pod install
  5. macOS needs the same two pods: the macOS plugin (macos/tesseract_ocr.podspec) compiles the same shared Swift source and links the same libtesseract, so an app that builds for macOS declares SwiftyTesseract401 (by :podspec) and libtesseract (by :path) in its macos/Podfile too — pointing at the plugin's ios/ directory, which is where the podspecs and the xcframework live. example/macos/Podfile is a working reference.

Android SDK Support

The plugin is configured to compile against the latest Android SDK (API 35) and has a minimum SDK version of 16, providing broad compatibility.

Web Setup (Tesseract.js)

Web support uses Tesseract.js (v6.0.1) compiled to WebAssembly (OCREngine.tesseract / OCREngine.defaultEngine). Apple Vision (OCREngine.vision) remains iOS-only and throws an UnsupportedError on Web.

  • Automatic CDN Loading: By default, the Web plugin dynamically loads tesseract.min.js (v6.0.1) from jsDelivr on first use when window.Tesseract is not already present.
  • Self-Hosting / Offline / Strict CSP: If you prefer to self-host tesseract.js or restrict external scripts via CSP, include <script src="...tesseract.min.js"></script> in your web/index.html before flutter_bootstrap.js.
  • Language Data: Bundled assets/tessdata/*.traineddata files listed in assets/tessdata_config.json are served directly from Flutter Web's asset bundle (gzip: false), supporting both LSTM (eng.traineddata, financial.traineddata) and legacy (OCRB.traineddata) models. You can also supply a custom OCRConfig(tessDataPath: ...) URL.

macOS Setup & Prerequisites

macOS support runs the same in-process Tesseract engine as iOS (SwiftyTesseract 4.0.1 on top of libtesseract) through the shared Swift plugin source — the machine does not need a tesseract binary installed. Apple Vision (OCREngine.vision) remains iOS-only and is not supported on macOS. Language .traineddata files ship in your Flutter app's assets/tessdata/ directory just like on mobile—no separate per-machine language setup is required for English (eng) or other bundled trained data.

Prerequisites

  1. Flutter macOS Desktop Support: Ensure Flutter macOS desktop is enabled (flutter config --enable-macos-desktop) along with Xcode 12.0 or later.
  2. Tesseract binary (libtesseract.xcframework): macOS links the same binary iOS does, and it is not distributed through pub.dev or CocoaPods. Download libtesseract-0.2.0.xcframework.zip from the libtesseract releases page and drop the unzipped libtesseract.xcframework next to ios/libtesseract.podspec in the plugin checkout — see CUSTOM_PODS_README.md. The podspec raises a named error when it is missing, instead of failing later at link time.
  3. SPM for direct consumers: an app that consumes the plugin through Swift Package Manager (rather than flutter pub add) adds the plugin root, whose Package.swift targets iOS 11+ and macOS 10.13+ and pulls SwiftyTesseract itself.
  4. App Sandbox Configuration: If your macOS app uses App Sandbox, you must disable it in macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements:
    <key>com.apple.security.app-sandbox</key>
    <false/>
    (This is already configured in example/macos/Runner/.)

Linux Setup & Prerequisites

Linux support uses the system Tesseract library installed via your distribution's package manager.

Prerequisites

  1. Flutter Linux Desktop Support: Ensure Flutter Linux desktop is enabled (flutter config --enable-linux-desktop).

  2. Install Tesseract and Leptonica:

    Ubuntu/Debian:

    sudo apt-get install libtesseract-dev libleptonica-dev

    Fedora/RHEL:

    sudo yum install tesseract-devel leptonica-devel

    Arch Linux:

    sudo pacman -S tesseract leptonica
  3. Verify Installation:

    tesseract --version

The plugin uses the system Tesseract library directly via C++ interop, providing native performance without bundled binaries.

Windows Setup & Prerequisites

Windows support uses the same Tesseract engine and tesseract_ocr method channel as Linux, implemented as a C++ CMake plugin. OCREngine.vision stays iOS-only and is rejected on Windows; every other engine value runs on Tesseract.

Prerequisites

  1. Flutter Windows Desktop Support: Enable it with flutter config --enable-windows-desktop. You also need Visual Studio 2022 with the "Desktop development with C++" workload, which provides MSVC and CMake 3.14 or later.

  2. Install Tesseract and Leptonica with their development files. The plugin links both libraries and copies their DLLs next to your executable, so a runtime-only install is not enough — it needs include/tesseract/capi.h and the import libraries. Any one of these works:

    vcpkg:

    vcpkg install tesseract

    MSYS2:

    pacman -S mingw-w64-x86_64-tesseract

    UB-Mannheim installer: enable "Install development files" so include/ and lib/ land in the prefix, then point the configure step at it:

    $env:TESSERACT_ROOT = "C:\Program Files\Tesseract-OCR"
    flutter build windows

    The plugin also probes the standard prefixes (%ProgramFiles%\Tesseract-OCR, the 32-bit one, and the per-user install), so an installer in the default location needs no configuration at all.

  3. Trained data: eng ships with the installer. Other languages are picked up from the Tesseract prefix's tessdata/, or from the assets/tessdata/ set the plugin copies into the app's documents directory like every other platform, or from a path you pass as OCRConfig(tessDataPath: ...). When no path is supplied the plugin also honours TESSDATA_PREFIX.

If Tesseract cannot be found, the build stops with the exact packages to install rather than producing a plugin DLL that would fail to load at runtime.

Usage

Import the package:

import 'package:tesseract_ocr/tesseract_ocr.dart';
import 'package:tesseract_ocr/ocr_engine_config.dart';

To perform OCR, use the TesseractOcr.extractText method. You can pass an optional OCRConfig object to specify the engine and other options.

If the image is already in memory — a camera frame, a picked file's bytes — use TesseractOcr.extractTextFromBytes instead of writing a temporary file first. It takes the same OCRConfig:

import 'dart:typed_data';

// `bytes` is a complete encoded image: exactly the file content an image path
// would have pointed at.
final Uint8List bytes = await pickImageBytes();
final String text = await TesseractOcr.extractTextFromBytes(
  bytes,
  config: const OCRConfig(language: 'eng', engine: OCREngine.tesseract),
);

Each platform takes the bytes through its own engine entry point — a bitmap on Android, a typed array on Web, a data buffer on Apple platforms — so no file is written. The Linux engine, which drives the tesseract command line, does write the bytes to a temporary file for the duration of the recognition, and deletes it again.

Future<void> _performOcr(String imagePath) async {
  try {
    // Default usage (uses OCREngine.defaultEngine, language 'eng')
    // String extractedText = await TesseractOcr.extractText(imagePath);

    // Example: Using Tesseract engine with a specific language
    final tesseractConfig = OCRConfig(
      language: 'eng', // Must match a .traineddata file in assets/tessdata
      engine: OCREngine.tesseract,
      // Optional Tesseract options:
      // options: {
      //   TesseractConfig.preserveInterwordSpaces: '1',
      //   TesseractConfig.pageSegMode: PageSegmentationMode.autoOsd,
      //   TesseractConfig.debugFile: '/path/to/debug.log', // Example option
      // },
    );
    String extractedTextTesseract = await TesseractOcr.extractText(
      imagePath,
      config: tesseractConfig,
    );
    print('Extracted Text (Tesseract): $extractedTextTesseract');

    // Example: Using Apple Vision engine (iOS only)
    final visionConfig = OCRConfig(
      engine: OCREngine.vision,
      language: 'eng', // Vision engine may also use language hint
    );
     // Check if running on iOS before using Vision
    if (Platform.isIOS) {
      String extractedTextVision = await TesseractOcr.extractText(
        imagePath,
        config: visionConfig,
      );
      print('Extracted Text (Vision): $extractedTextVision');
    }


  } catch (e) {
    print('Error performing OCR: $e');
  }
}

Orientation & script detection (OSD)

TesseractOcr.detectOrientationAndScript mirrors pytesseract.image_to_osd: it returns an OsdResult carrying the page rotation (orientationDegrees, rotate the image by it to make it upright), the detected writing script (scriptName), and a confidence for each. Use it to auto-rotate or decline an image before running extractText.

final osd = await TesseractOcr.detectOrientationAndScript(
  imagePath,
  config: const OCRConfig(language: 'osd'), // needs osd.traineddata
);
print('Rotate by ${osd.orientationDegrees}°, script: ${osd.scriptName}');

OSD is a Tesseract engine capability: OCREngine.vision is rejected, and the web build runs it through tesseract.js. It needs a legacy-capable traineddata — bundle osd.traineddata under assets/tessdata/ and list it in tessdata_config.json (or pass OCRConfig(tessDataPath: ...)).

Language default: detection classifies with the legacy templates of the osd model, so a call that names no language (config omitted or no language set on the web/Linux/Apple handlers) runs on osd — the OCR default eng carries no legacy templates and would answer TESSDATA_NOT_FOUND. An explicit OCRConfig(language: ...) is honoured as given.

Options: OCRConfig.options travel with the call and are applied by the engines that accept Tesseract variables (iOS, Linux, Web); tessedit_pageseg_mode becomes --psm on Linux, setVariable/setParameters elsewhere.

Platform matrix: iOS, macOS and Linux run the native detector (30s watchdog, OSD_TIMEOUT on a hung decode); Web runs tesseract.js worker.detect(); Android answers UNSUPPORTED_OSD (the bundled tesseract4android 4.8.0 binding exposes no OSD result API) — instead of a MissingPluginException. macOS gained the detector when it moved onto the shared Swift plugin; before that it drove the tesseract executable, which cannot return a structured result.

Extracting hOCR (layout-aware output)

Alongside plain text, the plugin can return hOCR — an HTML-like, layout-aware representation of the recognized text where every line, word and symbol carries its bounding box. Use it when you need the structure of the page (positions, word/line grouping) rather than just the characters:

import 'package:tesseract_ocr/tesseract_ocr.dart';
import 'package:tesseract_ocr/ocr_engine_config.dart';

Future<void> _performHocr(String imagePath) async {
  try {
    final hocr = await TesseractOcr.extractHocr(
      imagePath,
      config: const OCRConfig(
        language: 'eng',
        engine: OCREngine.tesseract,
      ),
    );
    print('hOCR:\n$hocr');
  } catch (e) {
    print('Error performing hOCR: $e');
  }
}
  • extractHocr has the same signature and options as extractText; only the returned format differs.
  • It is produced by the Tesseract engine, which backs Android, Web, macOS, iOS and Linux.
  • Apple's Vision engine (OCREngine.vision) has no hOCR output: requesting hOCR with it throws an UnsupportedError. Use OCREngine.tesseract or OCREngine.defaultEngine for hOCR.

OCRConfig

The OCRConfig class allows detailed configuration of the OCR process:

  • language (String): The language code (e.g., 'eng', 'fas'). Required for the Tesseract engine, usually corresponds to the .traineddata file prefix. Can be used as a hint for the Vision engine. Defaults to 'eng'.
  • engine (OCREngine): The OCR engine to use (OCREngine.vision, OCREngine.tesseract, or OCREngine.defaultEngine). Defaults to OCREngine.defaultEngine (Vision on iOS; Tesseract on Android, macOS, and Web).
  • tessDataPath (String?): A tessdata directory already on the device — a downloaded language pack, unpacked archive, or shared storage. Set it and the asset copy is skipped: the engine is pointed at that directory, which must hold <lang>.traineddata directly or under a tessdata/ subdirectory, or recognition is refused with tessdata-path-invalid. Ignored by OCREngine.vision, which reads no .traineddata. On Web it is the langPath URL the Tesseract.js worker loads from. Leave it unset to use the bundled assets/tessdata/ set.
  • options (Map<String, dynamic>?): A map of additional configuration options. Which keys each platform honours:
    • Android, macOS, Linux and Web (Tesseract engine): passed to the Tesseract engine. Use keys from TesseractConfig or any valid Tesseract configuration variable name (e.g., 'preserve_interword_spaces', 'tessedit_pageseg_mode'). Values should be strings. tessedit_pageseg_mode selects the page segmentation mode and tessedit_ocr_engine_mode the engine mode; every other key is set as a Tesseract variable.
    • iOS (Vision engine): Vision has no Tesseract variable set. TesseractConfig.recognitionLevel ('fast' or 'accurate', default 'accurate') and TesseractConfig.usesLanguageCorrection (true or false, default true) are honoured; any other key is logged as ignored rather than silently accepted.
    • A value a platform cannot apply is dropped and logged, never guessed: an unsupported page segmentation mode keeps the engine default, and an unparsable boolean keeps Vision's default.

See ocr_engine_config.dart for the OCREngine, TesseractConfig, and PageSegmentationMode enums and classes.

Example

Check the example directory for a complete Flutter app demonstrating how to use the plugin, select images, choose the OCR engine, and display results.

Running the Web Example App

cd example
flutter pub get
flutter run -d chrome

Running the Web Integration Test

cd example
flutter test integration_test/tesseract_ocr_web_test.dart -d chrome

Running the macOS Example App

cd example
flutter pub get
flutter run -d macos

Running the macOS Integration Test

cd example
flutter test integration_test/tesseract_ocr_macos_test.dart -d macos

Running the Linux Example App

cd example
flutter pub get
flutter run -d linux

Running the Linux Integration Test

cd example
flutter test integration_test/tesseract_ocr_linux_test.dart -d linux

Running the Linux Integration Test in Docker (headless)

docker build -f example/docker/linux.Dockerfile -t tesseract-ocr-linux-test .
docker run --rm tesseract-ocr-linux-test

Web Setup (Tesseract.js)

Web support uses tesseract.js compiled to WebAssembly. The library is loaded dynamically from a CDN on first use.

Content Security Policy (CSP)

If your app uses a strict Content Security Policy, you must allowlist the jsDelivr CDN in your web/index.html:

<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://cdn.jsdelivr.net;">

Alternatively, you can self-host tesseract.min.js by including it in your web/index.html before the Flutter bootstrap script.

About

Tesseract OCR for flutter

Resources

Stars

105 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages