Introduction
This section describes how to use the PrizmDoc OCR REST API to perform an OCR operation on an image running the OCR Reader Worker in a Docker container.
See the OCR Reader Sample on our GitHub page for details on how to use the PrizmDoc OCR REST API.
Step 1: Run OCR Reader Worker
Run the OCR Reader Worker as a Docker container as described in the How to Run a Worker topic.
Step 2: Upload Your Source Document
- Upload the source document that you want to convert.
- This can be a document of any format supported by the PrizmDoc OCR REST API.
- In response to this request you will receive a file ID that is used to reference the source document in later requests.
- See the Work File API for more details about uploading work files.
Example
POST http://localhost:18681/PCCIS/V1/WorkFile?FileExtension=png
Content-Disposition: form-data; name="image"; filename="testimage.png"
Content-Type: image/png
[binary data]
200 OK
Content-Type: application/json
{
"fileId": "tiUxPsiBvLW-JKEVkO93CA",
"fileExtension": "png"
}
Step 3: Create a Process of the ocrReaders Type
- Using the file ID you obtained for the source document in Step 2, you can now start the process to OCR the document. This is accomplished by sending a POST request to the Process Manager to start a new OCR process on the OCR Reader Worker.
Example
POST http://localhost:3000/v1/processes/ocrReaders
Content-Type: application/json
{
"input": {
"source": {
"fileId": "XahylGOjtzdGcIdFBH6Wsg"
},
"fields": [
{
"area": {
"x": 50,
"y": 50,
"width": 700,
"height": 500
}
}
],
"minimumCharacterConfidence": 0,
"defaultHorizontalResolution": 300
}
}
200 OK
Content-Type: application/json
{
"processId": "3UFCzaXATPiuHEMws4IWQA",
"state": "processing",
"expirationDateTime": "2023-08-03T01:58:10.696Z",
"input": {
"source": {
"fileId": "tiUxPsiBvLW-JKEVkO93CA"
},
"fields": [
{
"area": {
"x": 50,
"y": 50,
"width": 700,
"height": 500
}
}
],
"minimumCharacterConfidence": 0,
"defaultHorizontalResolution": 300
}
}
Step 4: Check Status of the OCR Readers Process
- The POST request you sent in Step 3 will return immediately before the operation completes. You need to check the status of the process by sending a GET request to the resource you just created.
- In response to this request, JSON that includes a
state
property will be returned. When this property is "complete", the JSON response will also include anoutput
property which means you can proceed to the next step. When this property has an "error", the JSON response will includeerrorCode
anderrorDetails
properties with details about the error.
Examples
Successful Response:
GET http://localhost:3000/v1/processes/ocrReaders/3UFCzaXATPiuHEMws4IWQA
200 OK
Content-Type: application/json
{
"processId": "3UFCzaXATPiuHEMws4IWQA",
"state": "complete",
"expirationDateTime": "2023-08-03T01:58:10.000Z",
"input": {
"source": {
"fileId": "tiUxPsiBvLW-JKEVkO93CA"
},
"fields": [
{
"area": {
"x": 50,
"y": 50,
"width": 700,
"height": 500
}
}
],
"minimumCharacterConfidence": 0,
"defaultHorizontalResolution": 300
},
"output": {
"fileId": "FdwzTOdlrh8w2gq56YEBUA"
}
}
Error response when source document is a file format that is not supported by the OCR API:
GET http://localhost:3000/v1/processes/ocrReaders/3UFCzaXATPiuHEMws4IWQA
200 OK
Content-Type: application/json
{
"input": {
"source": {
"fileId": "tiUxPsiBvLW-JKEVkO93CA"
}
},
"processId": "3UFCzaXATPiuHEMws4IWQA",
"state": "error",
"errorCode": "UnsupportedFileFormat",
"errorDetails": {
"in": "process",
"at": "input.source.fileId"
},
"expirationDateTime": "2023-08-03T01:58:10.000Z"
}
Step 5: Download a File with OCR Results
- Once the OCR readers process completes successfully, a file with OCR results in JSON format is available for download.
- A work file ID is made available for each successfully processed document in the
output
property from the JSON response retrieved in Step 4. - See the Work File API for more details about downloading work files.
Example
GET http://localhost:18681/PCCIS/V1/WorkFile/FdwzTOdlrh8w2gq56YEBUA
200 OK
Content-Type: application/json
{
"fields": [
{
"area": {
"x": 172,
"y": 167,
"width": 425,
"height": 291
},
"confidence": 76,
"text": "Sample Text",
"orientation": 0
}
]
}