Forms Recognizer API – Analyze Form

The Analyze Form operation extracts Key/Value pairs for the given document.

API Referencehttps://bit.ly/2NvTaCg

Pre-requisites

Image Requirements

  • Image needs to be PDF, JPEG, PNG

Analyze Form Operation

  • Launch Postman
  • Append your endpoint URL from the pre-requisites step with /formrecognizer/v1.0-preview/custom/models/{id}/analyze[?keys]
  • Where id – Model Id retrieved from Train Model endpoint.
  • Provide the subscription key and content-type in Headers tab as shown below.
  • In the Body tab, choose form-data and type the key as form and beside it click the down arrow to choose file as shown below.
  • Select the “Invoice_6.pdf” file from the Train folder downloaded from from here.
  • Click the Send button and you will get the output of the pdf form in Key/Value pairs as shown below.
 {
    "status": "success",
    "pages": [
        {
            "number": 1,
            "height": 792,
            "width": 612,
            "clusterId": 0,
            "keyValuePairs": [
                {
                    "key": [
                        {
                            "text": "Address:",
                            "boundingBox": [
                                57.3,
                                683.0,
                                100.5,
                                683.0,
                                100.5,
                                673.7,
                                57.3,
                                673.7
                            ]
                        }
                    ],
                    "value": [
                        {
                            "text": "14564 Main St.",
                            "boundingBox": [
                                57.3,
                                672.3,
                                124.3,
                                672.3,
                                124.3,
                                658.7,
                                57.3,
                                658.7
                            ],
                            "confidence": 0.86
                        },
                        {
                            "text": "Saratoga, CA 94588",
                            "boundingBox": [
                                57.3,
                                657.7,
                                147.3,
                                657.7,
                                147.3,
                                645.0,
                                57.3,
                                645.0
                            ],
                            "confidence": 0.86
                        }
                    ]
                },
                {
                    "key": [
                        {
                            "text": "Invoice For:",
                            "boundingBox": [
                                316.1,
                                683.1,
                                368.2,
                                683.1,
                                368.2,
                                673.7,
                                316.1,
                                673.7
                            ]
                        }
                    ],
                    "value": [
                        {
                            "text": "First Up Consultants",
                            "boundingBox": [
                                374.0,
                                687.9,
                                472.0,
                                687.9,
                                472.0,
                                673.7,
                                374.0,
                                673.7
                            ],
                            "confidence": 1.0
                        },
                        {
                            "text": "1234 King St",
                            "boundingBox": [
                                373.9,
                                673.0,
                                433.7,
                                673.0,
                                433.7,
                                658.7,
                                373.9,
                                658.7
                            ],
                            "confidence": 1.0
                        },
                        {
                            "text": "Redmond, WA 97624",
                            "boundingBox": [
                                373.8,
                                659.2,
                                472.3,
                                659.2,
                                472.3,
                                645.0,
                                373.8,
                                645.0
                            ],
                            "confidence": 1.0
                        }
                    ]
                },
                {
                    "key": [
                        {
                            "text": "Page",
                            "boundingBox": [
                                448.6,
                                96.1,
                                471.9,
                                96.1,
                                471.9,
                                86.7,
                                448.6,
                                86.7
                            ]
                        }
                    ],
                    "value": [
                        {
                            "text": "1 of",
                            "boundingBox": [
                                491.9,
                                96.1,
                                508.4,
                                96.1,
                                508.4,
                                86.7,
                                491.9,
                                86.7
                            ],
                            "confidence": 0.86
                        }
                    ]
                },
                {
                    "key": [
                        {
                            "text": "__Tokens__",
                            "boundingBox": [
                                0.0,
                                0.0,
                                0.0,
                                0.0,
                                0.0,
                                0.0,
                                0.0,
                                0.0
                            ]
                        }
                    ],
                    "value": [
                        {
                            "text": "Contoso Suites",
                            "boundingBox": [
                                38.0,
                                716.2,
                                188.0,
                                716.2,
                                188.0,
                                686.4,
                                38.0,
                                686.4
                            ],
                            "confidence": 0.86
                        },
                        {
                            "text": "1",
                            "boundingBox": [
                                532.7,
                                96.1,
                                538.2,
                                96.1,
                                538.2,
                                86.7,
                                532.7,
                                86.7
                            ],
                            "confidence": 0.86
                        }
                    ]
                }
            ],
            "tables": [
                {
                    "id": "table_0",
                    "columns": [
                        {
                            "header": [
                                {
                                    "text": "Invoice Number",
                                    "boundingBox": [
                                        38.5,
                                        585.2,
                                        113.4,
                                        585.2,
                                        113.4,
                                        575.8,
                                        38.5,
                                        575.8
                                    ]
                                }
                            ],
                            "entries": [
                                [
                                    {
                                        "text": "7689302",
                                        "boundingBox": [
                                            38.5,
                                            549.8,
                                            77.3,
                                            549.8,
                                            77.3,
                                            536.2,
                                            38.5,
                                            536.2
                                        ],
                                        "confidence": 1.0
                                    }
                                ]
                            ]
                        },
                        {
                            "header": [
                                {
                                    "text": "Invoice Date",
                                    "boundingBox": [
                                        139.7,
                                        585.2,
                                        198.5,
                                        585.2,
                                        198.5,
                                        575.8,
                                        139.7,
                                        575.8
                                    ]
                                }
                            ],
                            "entries": [
                                [
                                    {
                                        "text": "3/09/2015",
                                        "boundingBox": [
                                            139.7,
                                            548.1,
                                            184.0,
                                            548.1,
                                            184.0,
                                            536.2,
                                            139.7,
                                            536.2
                                        ],
                                        "confidence": 1.0
                                    }
                                ]
                            ]
                        },
                        {
                            "header": [
                                {
                                    "text": "Invoice Due Date",
                                    "boundingBox": [
                                        240.5,
                                        585.2,
                                        321.0,
                                        585.2,
                                        321.0,
                                        575.8,
                                        240.5,
                                        575.8
                                    ]
                                }
                            ],
                            "entries": [
                                [
                                    {
                                        "text": "6/29/2016",
                                        "boundingBox": [
                                            240.5,
                                            549.0,
                                            284.8,
                                            549.0,
                                            284.8,
                                            536.2,
                                            240.5,
                                            536.2
                                        ],
                                        "confidence": 1.0
                                    }
                                ]
                            ]
                        },
                        {
                            "header": [
                                {
                                    "text": "Charges",
                                    "boundingBox": [
                                        341.3,
                                        585.2,
                                        381.2,
                                        585.2,
                                        381.2,
                                        575.8,
                                        341.3,
                                        575.8
                                    ]
                                }
                            ],
                            "entries": [
                                [
                                    {
                                        "text": "$22,123.24",
                                        "boundingBox": [
                                            380.6,
                                            548.5,
                                            430.5,
                                            548.5,
                                            430.5,
                                            536.2,
                                            380.6,
                                            536.2
                                        ],
                                        "confidence": 1.0
                                    }
                                ]
                            ]
                        },
                        {
                            "header": [
                                {
                                    "text": "VAT ID",
                                    "boundingBox": [
                                        442.1,
                                        590.0,
                                        474.8,
                                        590.0,
                                        474.8,
                                        575.8,
                                        442.1,
                                        575.8
                                    ]
                                }
                            ],
                            "entries": [
                                [
                                    {
                                        "text": "QR",
                                        "boundingBox": [
                                            447.7,
                                            549.8,
                                            462.6,
                                            549.8,
                                            462.6,
                                            536.2,
                                            447.7,
                                            536.2
                                        ],
                                        "confidence": 1.0
                                    }
                                ]
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "errors": []
} 
  • If you would like to extract only particular set of keys from the form then you can include the additional “keys” parameter as part of the request to get the values related to that key. You will see the output as shown below. Note: the screenshot doesn’t include full output.