Bank Statement OCR
Bank Statement OCR

Bank statements are standard documents that record financial transactions for accounts over a fixed period of time. Data in bank statements needs to be extracted for various purposes, like, bookkeeping, income verification, customer onboarding, among others.

Traditionally, data from bank statements was extracted primarily through manual data entry.

Sample bank Statements
Sample bank Statements

But, handling abbreviated transaction descriptions, inconsistent date-time formats or specialised characters without context becomes challenging for humans.

Often entries are nullified or banks issue mid-statement adjustments which can be confusing. This is over and above the standard errors arising due to high volumes and fatigue. This not only reduces the efficiency of the process but makes it extremely time-consuming.

Enter bank statement OCR (Optical Character Recognition) – a technology that can automate data extraction from these statements. OCR is used under the hood for automated bank statement processing solutions that can extract specific data points contextually and automatically categorise expenses.

In this comprehensive guide, we'll explore everything relating to bank statement OCR, covering the concept of bank statement OCR, popular use cases for this technology and the various methods to perform OCR on bank statements, including the following:

Method Summary Pros Cons
Using MS-Excel's "Get Data" Converts bank statements from Word, Text, or XML files into Excel using Excel's "Get Data" feature. - Quick for one-off conversions
- Leverages familiar tools
- Requires pre-processing
- Limited accuracy for complex formats
- Post-processing needed
Using Online Converters Converts PDF or image bank statements to Excel via online tools, with limited customization. - Simple and accessible
- Supports PDF and image formats
- Potential security risks
- Inconsistent results
- Requires manual cleanup
Using Python Scripts Customizable OCR solution using Python for precise data extraction from bank statements. - Highly customizable
- Can handle complex extractions
- Requires programming skills
- Time-consuming setup
- Security and maintenance challenges
Using Large Language Models (LLMs) Uses AI models like GPT-4o to extract and structure text from bank statements flexibly. - Flexible and powerful
- Can handle various formats
- Accuracy varies
- Expensive for large volumes
- Requires effective prompt engineering
Using AI-based IDPs AI-powered IDPs for secure, accurate bank statement extraction with validation features. - Highly accurate
- Scalable
- Built-in validation
- Integrates with financial systems
- Setup may be complex
- Costs can be high for advanced features

By the end of this article, you'll have a thorough understanding of bank statement OCR and the tools available to implement this technology in your workflows. So, let’s get started.


What is Bank Statement OCR?

Before we jump into this, let us first cover what OCR stands for? 

💡
Optical Character Recognition (OCR) is a technology that converts different types of documents - such as scanned paper documents, PDFs, or images - into digital data. 

OCR works by analyzing the shapes and patterns of characters in an image and then translating these patterns into digital text that computers can process.

Bank Statement OCR technology focuses only on extracting data from bank statements. It identifies converting text and numbers on PDFs, text documents or images into machine-readable data, without compromising on the formatting. This technology automatically identifies and extracts critical information such as:

  • Account Holder Name: The person or entity holding the account.
  • Account Number: The unique identifier for the bank account.
  • Bank Name and Address: The details of the financial institution issuing the statement.
  • Statement Period: The time frame covered by the statement.
  • Transaction Details: Information about individual transactions, including dates, descriptions, and amounts.
  • Balance Information: Details about the account's balance at the beginning and end of the statement period.
  • Currency Used: The currency used in the bank statement. This can vary based on country.
Bank Statement OCR
Bank Statement OCR

Bank statement OCR has a wide range of applications across various industries and workflows. Here's a table outlining some of the most popular use cases:

Use Case Industry Short Description
Income Verification Banking & Finance Automates extraction of salary deposits and transaction history for efficient loan application assessment
Customer Onboarding Financial Services Streamlines KYC compliance by automating financial history verification
Insurance Applications Insurance Accelerates net worth assessments by automating extraction of transaction details and account information
Financial Reconciliation Accounting & Finance Automates matching of bank transactions with internal records for accurate financial reporting
Automated Tax Filing Taxation Speeds up compilation and analysis of income information for smoother tax filing processes

These use cases demonstrate the versatility and value of bank statement OCR across various functions and industries. Now, let's explore the different methods available for performing OCR on bank statements.


How to Perform OCR on Bank Statements

There are several methods to perform OCR on bank statements, ranging from simple online converters to AI-powered Intelligent Document Processing (IDP) solutions. However, we will be discussing the four most popular approaches through this article, along with their benefits and drawbacks. Before we dive into it, here is a quick summary of the methods:

Method Summary Pros Cons
Using MS-Excel's "Get Data" Converts bank statements from Word, Text, or XML files into Excel using Excel's "Get Data" feature. - Quick for one-off conversions
- Leverages familiar tools
- Requires pre-processing
- Limited accuracy for complex formats
- Post-processing needed
Using Online Converters Converts PDF or image bank statements to Excel via online tools, with limited customization. - Simple and accessible
- Supports PDF and image formats
- Potential security risks
- Inconsistent results
- Requires manual cleanup
Using Python Scripts Customizable OCR solution using Python for precise data extraction from bank statements. - Highly customizable
- Can handle complex extractions
- Requires programming skills
- Time-consuming setup
- Security and maintenance challenges
Using Large Language Models (LLMs) Uses AI models like GPT-4o to extract and structure text from bank statements flexibly. - Flexible and powerful
- Can handle various formats
- Accuracy varies
- Expensive for large volumes
- Requires effective prompt engineering
Using AI-based IDPs AI-powered IDPs for secure, accurate bank statement extraction with validation features. - Highly accurate
- Scalable
- Built-in validation
- Integrates with financial systems
- Setup may be complex
- Costs can be high for advanced features

1. Using MS-Excel's "Get Data" feature for bank statement OCR

This method works for bank statements that are in a few specific formats, like MS-Word files, Text files or even XML files. It is ideal for those who are looking for personal or quick, one-off conversion of their bank statements into Excel spreadsheets.

It leverages MS-Excel's built-in "Get Data" feature for the conversion. We will be taking an example of a sample bank statement in a Word file format to demonstrate this method. So, let's get started.

Step 1: Open an Excel spreadsheet, in your system and locate the Data tab at the top.

Step 2: Navigate to the option “New Query” > “From File” > “From Text”.

Step 3: You can then select the saved text file with the sample bank statement, select the delimiter and click on “Load”.

Step 4: If needed, you can adjust your data by selecting the “Transform” option as well.

Converting bank statements in word or text format to Excel
Converting bank statements in word or text format to Excel

Cons:

1. Selection of the correct "delimiter" is a major challenge when using this feature.
2. Usually requires pre-processing of bank statements for accurate conversion.
3. Requires significant post-processing effort under "Transform" section to preserve formatting
4. Limited accuracy for complex formats, such as, multi-line descriptions, nested tables, etc.

2. Using Online Converters for bank statement OCR

Online Converters offer a similar functionality. They can be used to convert bank statements in PDF as well as Image formats in addition to the formats discussed above. Some of them also offer paid versions for a higher volume of conversions.

We will take a sample bank statement (.PNG) and convert it to a spreadsheet format using an online converter. The following are the general steps one can follow for this:

Step 1: Visit the website of the online converter (such as, bankstatementconverter.com)

Step 2: Locate the option to convert images to Excel. Similarly, if your bank statement is in a PDF format, locate the option to convert PDF to Excel.

Step 3: Select the relevant option based on the format and upload your bank statement. Allow some time for it to be processed.

Step 4: Once complete, download the file in an Excel format.

Cons:

1. Limited accuracy for even simple layouts and lack of customisation for output
2. Potential security risks when uploading sensitive financial data to third-party online converters.
3. Inconsistent results across different bank statement formats.
4. Manual post-processing is often required to clean up and structure the data.
5. Time-consuming for large volumes of statements or frequent conversions.
6. No built-in data validation or error checking specific to financial information.
7. Lack of integration with accounting software or financial management systems.

3. Using Python scripts for bank statement OCR

This method requires programming skills. Basically, we leverage Python which offers powerful libraries for creating a custom OCR solution which specifically extracts bank statement data. 

Step 1: Install Required Libraries

First, we need to install the necessary libraries. We'll use PyPDF2 for PDF extraction, openpyxl for Excel manipulation, and re for regular expressions.

pip install PyPDF2 openpyxl

Step 2: Import Required Libraries

import PyPDF2
import re
import openpyxl
from openpyxl.styles import Font, Alignment

Step 3: Extract Text from PDF

def extract_text_from_pdf(pdf_path):
    with open(pdf_path, 'rb') as file:
        reader = PyPDF2.PdfReader(file)
        text = ''
        for page in reader.pages:
            text += page.extract_text()
    return text

This function opens the PDF, reads all pages, and concatenates the extracted text.

Step 4: Parse Extracted Text

def parse_transactions(text):
    transactions = []
    lines = text.split('\n')
    current_date = None
    
    for line in lines:
        date_match = re.match(r'(\d{2}/\d{2}/\d{4})', line)
        if date_match:
            current_date = date_match.group(1)
            continue
        
        transaction_match = re.match(r'(.+?)\s+([-+]?\$?\d+\.\d{2})\s+([-+]?\$?\d+\.\d{2})$', line)
        if transaction_match and current_date:
            description, amount, balance = transaction_match.groups()
            transactions.append({
                'date': current_date,
                'description': description.strip(),
                'amount': amount,
                'balance': balance
            })
    
    return transactions

This function goes through each line, identifies dates and transactions using regular expressions, and stores them in a list of dictionaries.

Step 5: Create an Excel File from the parsed text

def create_excel_from_transactions(transactions, excel_path):
    wb = openpyxl.Workbook()
    ws = wb.active
    ws.title = "Bank Statement"
    headers = ['Date', 'Description', 'Amount', 'Balance']
    for col, header in enumerate(headers, start=1):
        cell = ws.cell(row=1, column=col, value=header)
        cell.font = Font(bold=True)
        cell.alignment = Alignment(horizontal='center')
    for row, transaction in enumerate(transactions, start=2):
        ws.cell(row=row, column=1, value=transaction['date'])
        ws.cell(row=row, column=2, value=transaction['description'])
        ws.cell(row=row, column=3, value=transaction['amount'])
        ws.cell(row=row, column=4, value=transaction['balance'])
    for column in ws.columns:
        max_length = 0
        column_letter = column[0].column_letter
        for cell in column:
            try:
                if len(str(cell.value)) > max_length:
                    max_length = len(cell.value)
            except:
                pass
        adjusted_width = (max_length + 2)
        ws.column_dimensions[column_letter].width = adjusted_width
    wb.save(excel_path)
    print(f"Excel file created: {excel_path}")

This function creates an Excel workbook, adds headers, populates it with transaction data, adjusts column widths, and saves the file.

Download full code:



Cons:

1. Requires programming knowledge, limiting accessibility for non-technical users.
2. Needs regular maintenance and debugging to adapt to changes in bank statement formats.
3. May require additional libraries, increasing dependencies and potential compatibility issues.
4. Lacks built-in data validation specific to financial information.
5. Security concerns when handling sensitive financial data programmatically.
6. Limited scalability for processing large volumes of statements without additional infrastructure.

4. Using Large Language Models (LLMs) for bank statement OCR

Recent advancements in AI have led to the development of powerful Large Language Models (LLMs) that can be used for complex text extraction and understanding tasks.

a. Bank Statement OCR using GPT-4o User Interface

Step 1: Visit chatgpt.com and log in. Create a new conversation, switch to GPT-4o and have the sample Bank Statement in Word document ready.

💡
GPT-4o is essential because we need to have the capability to upload and download files.

Step 2: The tricky bit is getting the prompt right. We need to be clear in our instructions and state exactly what we want to get better outputs. We tried the following two prompts with drastically different results.

💡
Prompt 1: "Can you convert this Bank Statement into an Excel file?"
💡
Prompt 2: "Can you also include the Bank details and Account Summary as separate tables? Consolidate the transaction table into one with the columns, Date, Description, Deposits, Withdrawals, and Closing Balance in the Excel file?

Leave Withdrawal column blank for deposits.
Leave Deposits column blank for withdrawals.
Consider Fee as Withdrawals.
Calculate Closing balance for the day and populate the column accordingly."

You will notice Bank Details, Account Summary and Transaction Table in separate spreadsheets as well as a consolidated transaction table with auto-calculated Closing Balance for the day.


b. Bank Statement OCR using GPT-4o API

LLMs like, GPT can also be accessed via API. Since GPT cannot process images, the first step is to convert the bank statement image into text. This can be achieved using Optical Character Recognition (OCR) tools like Tesseract. Once the text is extracted, you can then use GPT to clean and structure the text.

Step 1: Import the relevant libraries.

import openai
import pandas as pd
from PIL import Image
import pytesseract
from io import StringIO


Step 2: Load the image of the bank statement so that the text can be extracted.

# Function to extract text from the image using Tesseract OCR
def extract_text_from_image(image_path):
    img = Image.open(image_path)
    return pytesseract.image_to_string(img)

Step 3. Process and Structure the Text Using GPT API

Once the text is extracted, it will likely be unstructured. GPT can be used to clean and format the text into a tabular structure suitable for an Excel spreadsheet. You will need to feed the extracted text to GPT, asking it to identify rows and columns (like dates, transactions, and amounts).


# Function to process text into CSV format using GPT API
def process_text_with_gpt(extracted_text):
    prompt = f"Here is the raw text from a bank statement:\n\n{extracted_text}\n\nCan you convert this into a CSV format with columns Date, Description, and Amount?"

    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=150
    )
    return response.choices[0].text.strip()

Step 4: Parse the structured CSV text into an Excel file.

# Function to convert structured CSV data into an Excel file
def convert_to_excel(csv_data, output_file):
df = pd.read_csv(StringIO(csv_data))
df.to_excel(output_file, index=False)
print(f"Excel file saved as {output_file}.")

Download Full Code:



Cons:

1. Potential privacy concerns when uploading sensitive financial data to third-party AI services.
2. Accuracy can be inconsistent, especially with poor quality images or unusual formatting.
3. High computational cost and potential latency issues for processing large volumes of statements.
4. Potential for hallucinations or fabricated data if the model encounters unfamiliar patterns.
5. May require significant prompt engineering to achieve consistent and accurate results.
6. Difficulty in integrating with existing financial systems or workflows without additional development.
7. Lack of built-in data validation specific to financial information and regulations.

5. Using AI-based IDPs for bank statement OCR

So far we have covered numerous ways of extracting data from bank statements, all with their unique challenges.

Thankfully, leveraging Intelligent Document Processing (IDPs) solutions is an easy and universal fix to all these issues.

Nanonets is one such example. We offer pre-trained models for bank statements as well as our revolutionary zero-training model that can be trained to extract data from any custom document in seconds.

You can preserve formatting, or layer it with additional formatting actions, such as adding/removing values based on logic, looking up against external databases (accurate and fuzzy matching) as well as reconciliation with other documents, like, Invoices, Receipts, etc.

We also seamlessly integrate with popular accounting software like Zero, Sage, Quickbooks as well as ERPs like Salesforce. Our data mapping feature allows complete control over your final output. There are advanced validation features built-in for an added layer of human approval. Moreover, the data is completely secure.

Let's take a look at how you can automate your bank statement processing using Nanonets.

Step 1: Visit the web application (app.nanonets.com). Create your account if you don't already have one and log in.

Step 2: Go to "New workflow" > "Pre-trained bank statement extractor". If you don't find this option, you can use their Zero-training extractor as well. Guide video here.

Step 3: Once you're done, simply upload your bank statements in PDF or Image format and allow a few seconds for processing. Once it is done, you can click on the file and see the results. Example below.

Bank Statement OCR using IDPs like Nanonets
Bank Statement OCR using IDPs like Nanonets
Why IDPs, like Nanonets are the best solution for bank statement OCR?

1. Adaptable to various bank statement formats without manual template creation. Has a zero-training extractor that can be deployed in under 10 seconds!
2. AI-based, so it learns and accuracy improves over time.
3. Can handle multi-page statements.
3. Built-in data validation and error checking specific to bank statements.
4. Seamless integration with existing financial systems and workflows, such as Quickbooks, Xero, Sage, Salesforce, etc. Has the option to map the data before exporting.
5. Fuzzy-match against external databases and add fields to the data before exporting.
6. HIPAA and GDPR compliant along with SoC certification. Offers best-in-class data security.
7. Supports multi-language (110+ languages) processing for international bank statements.


Summary

Bank statement OCR (Optical Character Recognition) is a technology that automates the extraction of data from bank statements, converting images or PDF files into machine-readable data. This method offers a faster and more accurate alternative to manual data entry, reducing errors and saving businesses both time and money. It helps with bank statement analysis to detect fraudulent activities like using fake bank statements.

Traditional manual data entry, while useful for context-heavy documents, can be inefficient for standardised documents like bank statements. OCR focuses on extracting key details such as account numbers, transaction descriptions, and balances, streamlining processes like income verification, customer onboarding, and financial reconciliation.

Several methods can be used for bank statement OCR, some of which we covered in the article above. Simple online converters or Excel's "Get Data" feature are quick to set up but may lack accuracy and present security risks. More advanced approaches include Python scripts that offer customisation but require technical knowledge and maintenance. Large Language Models (LLMs) like GPT-4 can structure extracted data efficiently but come with high costs and privacy concerns.

AI-based Intelligent Document Processing (IDP) solutions like Nanonets are the best one-stop solution for automating bank statement processing. It provides highly accurate, scalable, and secure platform, integrating easily with accounting software as well. It can handle advanced validation rules, help with multi-language processing, and provide end-to-end process automation so your bank statement workflows can run on autopilot.