Usage

This guide provides an overview of the OCR API and how to use it. For information on what OCR can do, please see here.

Running OCR on All Pages

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
POST /process
Content-Type: multipart/form-data; boundary=customboundary
Authorization: Token token="JWT Token"

--customboundary
Content-Disposition: form-data; name="file"; filename="Example Document.pdf"
Content-Type: application/pdf

<PDF data>
--customboundary
Content-Disposition: form-data; name="operations"
Content-Type: application/json

{
    "operations": [
        {
            "type": "performOcr",
            "pageIndexes": "all",
            "language": "english"
        }
    ]
}
--customboundary

Runnable Example

The JSON Web Token (JWT) we’ll encode will look like:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "iat": DATE_WHEN_JWT_WAS_ISSUED,
  "exp": DATE_WHEN_JWT_EXPIRES,
  "allowed_operations": {
    "operations": [
      [
        {
          "type": "performOcr",
          "pageIndexes": "all",
          "language": "english"
        }
      ]
    ]
  }
}

This JWT can be used to run OCR on any document, but it can’t be used for any other document operation.

Once you’ve generated your JWT, you can proceed to running OCR on the document. Here’s an example curl call:

Copy
1
2
3
4
5
curl -H "Authorization: Token token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhbGxvd2VkX29wZXJhdGlvbnMiOnsib3BlcmF0aW9ucyI6W1t7InR5cGUiOiJwZXJmb3JtT2NyIiwicGFnZUluZGV4ZXMiOiJhbGwiLCJsYW5ndWFnZSI6ImVuZ2xpc2gifV1dfSwiaWF0IjoxNTk4MDEwMTU3LCJleHAiOjE1OTgwMTM3NTd9.lLFaBqho8p22zVsrncaalw3EXNdJEP0ZRY5XbC22ayGmfnLVYI94mdDouIWtpLvfQafuFlS2zKDUHT8KUw4fyA" \
  -F file=@Example.pdf \
  -F operations="{\"operations\":[{\"type\": \"performOcr\",\"pageIndexes\": \"all\",\"language\": \"english\"}]}" \
  http://localhost:5000/process \
  --output result.pdf