Extract Data Easily with our AI-Powered OCR API


TextSense OCR#

TextSense OCR is a large-volume document image text conversion solution based on deep learning AI. Use this to extract data from invoices, forms, bank statements or any other kind of document.

Available Methods#

/textsense/job/build#

Use the REST API to request OCR work on documents in various formats from the TextSense server.

  • Method: POST

  • Endpoint: /v1/textsense/job/build

Important

You should run the Background Job Check API to check the status of a TextSense OCR operation. As this is an asynchronous operation you will need to supply the jobId for the process and wait for the status value to return success - then you will obtain the URL for the TextSense OCR output file.

Attributes#

Note

Attributes are case-sensitive and should be inside JSON for POST request, for example:

{
    "inputUri": "https://example.com/file1.pdf"
}

Attribute

Description

Required

inputUri

URL to the source file. 1

yes

options

Contains the options for the operation to be performed.

yes

“options” object#

Contains the extraJobs object.

Attribute

Description

Required

extraJobs

Defines the job details to be performed.

yes

“extraJobs” object#

Defines the job details for the OCR operation.

Attribute

Description

Required

type

This is the separator for the OCR operation. To perform OCR work, textSense is used as a fixed value.

yes

option

Option values to be applied to the OCR operation are transmitted in the form of a JSON object.

yes

“option” object#

Attribute

Description

Required

reqType

Set the recognition logic for OCR work. Use Document as a fixed value.

yes

reqOption

The default value is an empty json object. In addition to the basic recognition of {}, you can set additional settings for OCR work, such as SearchAPI to update the recognition target settings.

yes

outputType

Set the type of result file to be created through OCR work. Supported output types are pdf, json, excel, text, and text-split. text saves the text of the requested document as a single .txt file, and text-split saves the text of the requested document for each page.

yes

pages

Set the range to perform OCR work. The default is for all pages. Examples: all, 1-5, 1,2,3, etc. are possible.

no

“reqOption” object#

In addition to basic recognition, you can make additional settings for OCR work.

Attribute

Description

Required

PreProcessOption

This option allows you to perform special operations before OCR extraction. Keys for this are as follows:

Key

Description

denoising

Reduces noise in the original file.

scaleUp

Enlarges the original file.

RotationCorrection

Corrects the rotation of the original file.

no

ResultOption

This option allows you to specify options for the desired result. Keys for this are as follows:

Key

Description

Format

If set to PlainText, the table structure will be ignored in the recognized results.

WordCorrection

When set to Custom , you can use a word correction dictionary from an externally mounted directory.

no

CustomSetting

This option allows you to temporarily change/set the value of a custom setting. You can temporarily change/set the value of CustomSetting through reqOption for one request only. Keys for this are as follows:

Key

Description

TextInputMaxAxis

Image input size when detecting text.

TableInputMaxAxis

Table detects image input size.

TextScoreThreshold

Threshold for text detection score.

TableCellScoreThreshold

Threshold for table detection score.

CellAlignSearchMargin

Sets the margin for table cell alignment. The unit is a pixel, and as the value increases, it becomes less sensitive to rotation and errors, but the tendency for small cells to merge into one increases.

CellAlignGridMargin

Sets the size of the grid format when dividing the matrix for table cells. The units are pixels, and as the value increases, it becomes less sensitive to rotations and errors, but also increases the tendency for small cells to merge into one.

no

SearchAPI

This option allows you to extract data by adding special. Keys for this are as follows:

Key

Description

Type.

The name of the task you want to perform.

Name

The name of the task. This name becomes the return name in the results.

Key

Keys for navigation in tasks.

no

SearchAPI.Type Object definition#

FindRow#

This is an API that collects and returns data in the same row as the target containing a specific string.

  • If there are multiple rows with the same content, only the first row detected is returned.

  • The key value of the request JSON is compared based on the word element, and may not work properly if the spacing between words is large.

"reqOption" : {
   "SearchAPI" : [
        {
            "Type" : "FindRow",
            "Name" : "Test-Title",
            "Key"  : ["Keyword in row"]
        }
   ]
}

FindRightRow#

This uses the same algorithm as FindRow, but returns only those positions to the right of the search target in the results.

  • If there are multiple rows with the same content, only the first row detected is returned.

  • The key value of the request JSON is compared based on the word element, and may not work properly if the spacing between words is large.

"reqOption" : {
   "SearchAPI" : [
        {
            "Type" : "FindRightRow",
            "Name" : "Test-Title",
            "Key"  : ["Keyword in row"]
        }
   ]
}

FindCol#

This collects and returns data in the same column as the target that contains a specific string.

  • If there are multiple columns with the same content, only the first detected column is returned.

  • The key value of the request JSON is compared based on the word element, and may not work properly if the spacing between words is large.

"reqOption" : {
   "SearchAPI" : [
        {
            "Type" : "FindCol",
            "Name" : "Test-Title",
            "Key"  : ["Keyword in column"]
        }
   ]
}

FindBottomCol#

This uses the same algorithm as FindCol, but only returns the results located below the search target.

  • If there are multiple columns with the same content, only the first detected column is returned.

  • The key value of the request JSON is compared based on the word element, and may not work properly if the spacing between words is large.

"reqOption" : {
   "SearchAPI" : [
        {
            "Type" : "FindBottomCol",
            "Name" : "Test-Title",
            "Key"  : ["Keyword in column"]
        }
   ]
}

FindWord#

This request searches for and returns data containing a specific string.

  • The key value of the request JSON is compared based on the word element, and may not work properly if the spacing between words is large.

"reqOption" : {
   "SearchAPI" : [
        {
            "Type" : "FindWord",
            "Name" : "Test-Title",
            "Key"  : ["Keyword"]
        }
   ]
}

FindLine#

This request searches for and returns data on lines that contain a specific string.

  • FindLine performs a similar function to FindRow, but while FindRow aims to search tables, FindLine aims to search text lines.

  • Therefore, we recommend using FindRow when looking for data inside a table and FindLine when looking for data in a general document outside the table.

"reqOption" : {
   "SearchAPI" : [
        {
            "Type" : "FindLine",
            "Name" : "Test-Title",
            "Key"  : ["Keyword"]
        }
   ]
}

FindRegion#

This request collects and returns data contained within a specific rectangular region.

  • The FindRegion API, unlike other APIs, contains coordinates rather than letters in the key.

  • The coordinates are TL (Top-Left) and BR (Bottom-Right) of the area to be recognized.

"reqOption" : {
      "SearchAPI" : [
         {
            "Type" : "FindRegion",
            "Name" : "city",
            "Key"  : [
                [
                    217.218085106383,
                    156.75531914893617
                ],
                [
                    265.19680851063833,
                    174.2845744680851
                ]
            ]
         },{
            "Type" : "FindRegion",
            "Name" : "phone-number",
            "Key"  : [
                [
                    428.8377659574468,
                    296.7154255319149
                ],
                [
                    507.04787234042544,
                    320.9627659574469
                ]
            ]
         }
      ]
   }


Code Samples#

Payload#

{
     "inputUri": "https://yourfile.pdf",
     "options": {
         "extraJobs": [
             {
                 "type": "textSense",
                 "option": {
                     "reqType": "Document",
                     "reqOption": {
                         "SearchAPI": [
                             {
                                 "Type": "FindRegion",
                                 "Name": "city",
                                 "Key": [
                                     [
                                         217.218085106383,
                                         15675531914896317
                                     ],
                                     [
                                         265.19680851063833,
                                         174.2845744680851
                                     ]
                                 ]
                             },
                             {
                                 "Type": "FindRegion",
                                 "Name": "phone-number",
                                 "Key": [
                                     [
                                         428.8377659574468,
                                         296.7154255319149
                                     ],
                                     [
                                         507.04787234042544,
                                         320.9627659574469
                                     ]
                                 ]
                             }
                         ]
                     },
                     "outputType": "json",
                     "pages": "all"
                 }
             }
         ]
     }
 }

Response 2#

{
    "jobId": "6YSZD3U872ZYYFEDMQCQSGEEO8YSF5WA--151-300",
    "error": false,
    "status": 200,
    "credits": 21,
    "remainingCredits": 45036,
    "duration": 943
}

CURL#

curl --location --request POST 'https://api.pdf.co/v1/textsense/job/build' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
    "inputUri": "https://yourfile.pdf",
    "options": {
          "extraJobs": [
              {
                  "type": "textSense",
                  "option": {
                      "reqType": "Document",
                      "reqOption": {
                          "SearchAPI": [
                              {
                                  "Type": "FindRegion",
                                  "Name": "city",
                                  "Key": [
                                      [
                                          217.218085106383,
                                          15675531914896317
                                      ],
                                      [
                                          265.19680851063833,
                                          174.2845744680851
                                      ]
                                  ]
                              },
                              {
                                  "Type": "FindRegion",
                                  "Name": "phone-number",
                                  "Key": [
                                      [
                                          428.8377659574468,
                                          296.7154255319149
                                      ],
                                      [
                                          507.04787234042544,
                                          320.9627659574469
                                      ]
                                  ]
                              }
                          ]
                      },
                      "outputType": "json",
                      "pages": "all"
                  }
              }
          ]
      }
}'


Footnotes

1

Supports links from Google Drive, Dropbox, and PDF.co Built-In Files Storage. To upload files via the API check out the File Upload section. Note: If you experience intermittent Too Many Requests or Access Denied errors, please try to add cache: to enable built-in URL caching. (e.g cache:https://example.com/file1.pdf) For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.

2

Main response codes as follows:

Code

Description

200

Success

400

Bad request. Typically happens because of bad input parameters, or because the input URLs can’t be reached, possibly due to access restrictions like needing a login or password.

401

Unauthorized

402

Not enough credits

445

Timeout error. To process large documents or files please use asynchronous mode (set the async parameter to true) and then check status using the /job/check endpoint. If a file contains many pages then specify a page range using the pages parameter. The number of pages of the document can be obtained using the /pdf/info endpoint.