# Scanning and OCR (IRPCScanningAndOCR)

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Vault API](https://developer.m-files.com/APIs/gRPC-API/vault/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/

Runs server-side OCR: converts files to searchable PDF and recognizes text in page areas.

- **gRPC service:** `MFiles.IRPCScanningAndOCR`
- **Book and level:** [Vault API](https://developer.m-files.com/APIs/gRPC-API/vault/index.md), standard
- **Methods:** 8
- **Proto file:** [`mfiles/IRPCScanningAndOCR.proto`](https://developer.m-files.com/APIs/gRPC-API/downloads/proto/mfiles/IRPCScanningAndOCR.proto)

<a id="overview"></a>

## Overview

OCR runs on the server as a background operation of the calling session. A job is started,
polled and ended:

1. Check that server OCR is available with
   [GetScanningAndOCROptions](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/GetScanningAndOCROptions/index.md)
   (`allow_server_ocr`, `allowed_file_extensions`).
2. Start the job:
   - on a file you upload:
     [OCROperation_BeginAfterUpload](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_BeginAfterUpload/index.md),
     or
   - on a file of a checked-out document in the vault:
     [OCROperation_Begin](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_Begin/index.md).
3. Poll [OCROperation_Status](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_Status/index.md) until `done`.
4. End the job, which also releases it:
   - [OCROperation_EndWithDownload](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_EndWithDownload/index.md)
     returns the recognized texts and a download of the resulting PDF, or
   - [OCROperation_End](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_End/index.md) replaces the
     document's file in the vault with the resulting PDF.

The `background_op_id` exists only in the memory of the server that started the job: poll and
end the job on the same server. After the job has ended, or after
it failed and the failure was reported, the ID is no longer valid and calls fail with "The
parameter is incorrect.".

**Operation types** ([OCROperationType](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.OCROperationType/index.md)):
`..._CONVERT_TO_SEARCHABLE_PDF` and `..._CONVERT_TO_SEARCHABLE_ARCHIVE_PDF` (PDF/A-1b) produce a
PDF; `..._RECOGNIZE_SPECIFIC_BLOCKS` reads the text of the areas given in `pages`; `..._RECOGNIZE_ANY_BLOCKS` returns the text areas it
finds; the combined types do both.

All methods need a vault session. Files are covered in
[Files](https://developer.m-files.com/APIs/gRPC-API/runtime/files/index.md).

<a id="methods"></a>

## Methods

| Method | Summary | Facts |
|---|---|---|
| [GetOCRUploadedFileStatus](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/GetOCRUploadedFileStatus/index.md) | Gets the state of an OCR job started with OCRUploadedFile and, when it has completed, its result as a `file_ref`. Optionally requests the cancellation of the job. | `write` `session` |
| [GetScanningAndOCROptions](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/GetScanningAndOCROptions/index.md) | Gets whether scanning and client- and server-side OCR are enabled for the vault, and for which file types. | `read` `session` `idempotent` `returns metadata structure version` |
| [OCROperation_Begin](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_Begin/index.md) | Starts an OCR job on a file of a document that the caller has checked out. | `write` `session` `idempotent` `returns metadata structure version` |
| [OCROperation_BeginAfterUpload](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_BeginAfterUpload/index.md) | Starts an OCR job on a file that the caller uploaded with UploadTempFile. | `write` `session` `idempotent` `returns metadata structure version` |
| [OCROperation_End](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_End/index.md) | Ends an OCR job started with OCROperation_Begin and replaces the document's file with the resulting PDF. | `write` `session` `returns metadata structure version` |
| [OCROperation_EndWithDownload](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_EndWithDownload/index.md) | Ends an OCR job and returns its results: the recognized texts and a download of the PDF. | `write` `session` `returns metadata structure version` |
| [OCROperation_Status](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCROperation_Status/index.md) | Gets the progress of an OCR job, and optionally cancels it. | `write` `session` `idempotent` `returns metadata structure version` |
| [OCRUploadedFile](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCScanningAndOCR/OCRUploadedFile/index.md) | Starts an OCR job that converts the file of a stateless upload to a searchable PDF. | `write` `session` |
