OCR languages Pixelnetica™ Document Scanning SDK for Apple iOS

OCR needs language data. DSSDK ships orientation/script detection data in the framework so it works on first launch with no network, and downloads recognition languages on demand.

Bundled offline data (OSD)

Orientation and script detection (OSD) data is bundled and decrypted on first use — no download, no network. Ask for its directory:

import DocScanningSDK

// Synchronous:
let osdDir = try PxBundledOcrData.osdDirectory()
// or asynchronous:
PxBundledOcrData.osdDirectory { dir, error in /* ... */ }

This is what lets the SDK detect a page’s orientation and script offline, before any language pack is installed.

Hosting the language files

DSSDK recognises 100+ languages. Their recognition data ships as a single archive that you download once and make available to your app:

Download the language archive, unzip it, and either host the files on a server your app can reach or bundle them in the app. The SDK downloads each language from a base URL you provide — the location the unzipped files live under.

Downloading language packs

Recognition languages (English, German, …) are downloaded on demand with PxLanguageDownloader. You give it a language code, a base URL, an output directory, and a delegate that receives progress and completion:

let downloader = PxLanguageDownloader(
    "eng", from: baseURL, withOutDir: languagesDir, andDelegate: self)
downloader.start()   // downloader.cancel() to abort

The delegate (PxLanguageDownloaderDelegate) reports onLanguageDownloadProgress(_:progress:) and onLanguageDownloadFinished(_:error:). The output directory is the folder you later pass to PxTextReader as its language data.

Ready-to-use: the language picker

PxUiLanguagePickerScreen (SwiftUI PxUiLanguagePickerScreenView) presents the installed and available languages, handles search, and returns the user’s selection. It pairs with the OCR editor, which can present it to change languages and re-recognise. Its on-screen text is re-localisable through the strings table.

You tell the picker where to download from and where to store the files through its configuration. EasyScanner builds this in OCRLanguagePickerSupport.swift; point baseURL at the location where you host the language files:

PxUiLanguagePickerScreenConfiguration(
    outputDirectory: ocrLanguagesDirectory(),                    // where downloaded files are stored
    baseURL: "https://your-server.example.com/ocr-languages",    // your hosted language files
    selectionStore: OCRLanguageSelectionStore())

The sample passes PxUiLanguagePickerScreenConfiguration.defaultBaseURL (the Pixelnetica evaluation server) — replace it with your own URL for production. If you drive downloads yourself instead of using the picker, pass the same URL as the from: argument of PxLanguageDownloader (shown above).

Tips

  • OSD data is always available; recognition languages must be downloaded before first use of that language.
  • Pass several languages to PxTextReader at once by joining codes with + (for example "eng+fra").

See also

Top