<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

*   [init][1]
    *   [Parameters][2]
*   [extractText][3]
    *   [Parameters][4]
*   [writeDebugImages][5]
    *   [Parameters][6]
*   [clear][7]
*   [terminate][8]
*   [exportData][9]
    *   [Parameters][10]
*   [download][11]
    *   [Parameters][12]
*   [SortedInputFiles][13]
    *   [Properties][14]
*   [importFiles][15]
    *   [Parameters][16]
*   [recognize][17]
    *   [Parameters][18]

## init

Initialize the program and optionally pre-load resources.

### Parameters

*   `params` **[Object][19]?**&#x20;

    *   `params.pdf` **[boolean][20]** Load PDF renderer. (optional, default `false`)
    *   `params.ocr` **[boolean][20]** Load OCR engine. (optional, default `false`)
    *   `params.font` **[boolean][20]** Load built-in fonts.
        The PDF renderer and OCR engine are automatically loaded when needed.
        Therefore, the only reason to set `pdf` or `ocr` to `true` is to pre-load them. (optional, default `false`)

## extractText

Function for extracting text from image and PDF files with a single function call.
By default, existing text content is extracted for text-native PDF files; otherwise text is extracted using OCR.
To control how text from PDF files is handled, set the options in the `opt.usePDFText` object.
For more control, use `init`, `importFiles`, `recognize`, and `exportData` separately.

### Parameters

*   `files` &#x20;
*   `langs` **[Array][21]<[string][22]>**  (optional, default `['eng']`)
*   `outputFormat`   (optional, default `'txt'`)
*   `options`   (optional, default `{}`)

## writeDebugImages

### Parameters

*   `ctx` &#x20;
*   `compDebugArrArr` **[Array][21]<[Array][21]\<CompDebugNode>>**&#x20;
*   `filePath` **[string][22]**&#x20;

## clear

Clears all document-specific data.

## terminate

Terminates the program and releases resources.

## exportData

Export active OCR data to specified format.

### Parameters

*   `format` **(`"pdf"` | `"hocr"` | `"docx"` | `"xlsx"` | `"txt"` | `"text"`)**  (optional, default `'txt'`)
*   `minPage` **[number][23]** First page to export. (optional, default `0`)
*   `maxPage` **[number][23]** Last page to export (inclusive). -1 exports through the last page. (optional, default `-1`)

Returns **[Promise][24]<([string][22] | [ArrayBuffer][25])>**&#x20;

## download

Runs `exportData` and saves the result as a download (browser) or local file (Node.js).

### Parameters

*   `format` **(`"pdf"` | `"hocr"` | `"docx"` | `"xlsx"` | `"txt"` | `"text"`)**&#x20;
*   `fileName` **[string][22]**&#x20;
*   `minPage` **[number][23]** First page to export. (optional, default `0`)
*   `maxPage` **[number][23]** Last page to export (inclusive). -1 exports through the last page. (optional, default `-1`)

## SortedInputFiles

An object with this shape can be used to provide input to the `importFiles` function,
without needing that function to figure out the file types.
This is required when using ArrayBuffer inputs.

Type: [Object][19]

### Properties

*   `pdfFiles` **([Array][21]\<File> | [Array][21]<[string][22]> | [Array][21]<[ArrayBuffer][25]>)?**&#x20;
*   `imageFiles` **([Array][21]\<File> | [Array][21]<[string][22]> | [Array][21]<[ArrayBuffer][25]>)?**&#x20;
*   `ocrFiles` **([Array][21]\<File> | [Array][21]<[string][22]> | [Array][21]<[ArrayBuffer][25]>)?**&#x20;

## importFiles

Import files for processing.
An object with `pdfFiles`, `imageFiles`, and `ocrFiles` arrays can be provided to import multiple types of files.
Alternatively, for `File` objects (browser) and file paths (Node.js), a single array can be provided, which is sorted based on extension.

### Parameters

*   `files` **([Array][21]\<File> | FileList | [Array][21]<[string][22]> | [SortedInputFiles][13])**&#x20;

## recognize

Recognize all pages in active document.
Files for recognition should already be imported using `importFiles` before calling this function.
The results of recognition can be exported by calling `exportFiles` after this function.

### Parameters

*   `options` **[Object][19]**  (optional, default `{}`)

    *   `options.mode` **(`"speed"` | `"quality"`)** Recognition mode. (optional, default `'quality'`)
    *   `options.langs` **[Array][21]<[string][22]>** Language(s) in document. (optional, default `['eng']`)
    *   `options.modeAdv` **(`"lstm"` | `"legacy"` | `"combined"`)** Alternative method of setting recognition mode. (optional, default `'combined'`)
    *   `options.combineMode` **(`"conf"` | `"data"` | `"none"`)** Method of combining OCR results. Used if OCR data already exists. (optional, default `'data'`)
    *   `options.vanillaMode` **[boolean][20]** Whether to use the vanilla Tesseract.js model. (optional, default `false`)
    *   `options.config` **[Object][19]<[string][22], [string][22]>** Config params to pass to to Tesseract.js. (optional, default `{}`)

[1]: #init

[2]: #parameters

[3]: #extracttext

[4]: #parameters-1

[5]: #writedebugimages

[6]: #parameters-2

[7]: #clear

[8]: #terminate

[9]: #exportdata

[10]: #parameters-3

[11]: #download

[12]: #parameters-4

[13]: #sortedinputfiles

[14]: #properties

[15]: #importfiles

[16]: #parameters-5

[17]: #recognize

[18]: #parameters-6

[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

[21]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[24]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise

[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
