This script reads a PDF bank statement and exports the transaction data to an Excel file. It's specifically optimized for DBS/POSB bank statements but includes alternative parsing logic for other formats.
- Node.js (v14 or higher)
- pnpm
- Clone this repository or download the files
- Install dependencies:
pnpm install- Place your bank statement PDF file in the in e-statement folder and follow by the bank name like e-statement/dbs.
- Run the script:
pnpm start- The script will generate an Excel file named
bank-statement.xlsxin the same directory - For debugging purposes, the script also creates an
extracted-text.txtfile with the raw text content from the PDF
- Extracts transaction data including:
- Account number
- Transaction date
- Detailed description with comprehensive transaction details
- Withdrawal amount
- Deposit amount
- Balance
- Transaction category
- Handles multi-page DBS/POSB bank statements
- Processes multi-line transaction entries
- Captures complete recipient information across multiple lines
- Automatically categorizes transactions based on recipient information and description
- Provides category-based summaries showing totals for each transaction type
- Preserves important transaction details like:
- Recipient information (e.g., "TO: YOU TECHNOLOGIES GROUP (SG) PL")
- Merchant details for debit card transactions
- Card numbers and transaction dates
- Reference numbers and transfer IDs
- Company names and payment details for GIRO and Salary transactions
- Intelligently categorizes amounts as withdrawals, deposits, or balances
- Uses balance tracking to verify and correct transaction amounts
- Cleans up transaction descriptions for better readability
- Adds a summary row with total withdrawals and deposits
- Formats the Excel output with appropriate column widths
- Includes alternative parsing logic for non-DBS bank statements
The script uses several specialized functions to process the PDF content:
-
processDBSStatementData: Main parser optimized for DBS/POSB bank statements- Handles multi-line transaction entries
- Extracts account numbers, dates, descriptions, and amounts
- Collects recipient information across multiple lines until an amount appears
- Uses context clues to categorize amounts correctly
- Tracks balance changes to verify transaction amounts
-
processAmounts: Specialized function to categorize amounts- Uses keywords like "TO:", "FROM:", "TRANSFER", "PAYMENT" to determine transaction type
- Handles various amount formats and positions
- Uses balance tracking to verify withdrawal vs deposit
-
verifyTransactionAmounts: Ensures transaction amounts are correct- Uses balance changes to verify and correct withdrawal/deposit amounts
- Resolves ambiguities in transaction categorization
-
cleanupDescription: Improves description readability and categorizes transactions- Preserves important recipient/sender information
- Extracts merchant details for debit card transactions
- Handles different transaction types (FAST/PAYNOW, debit card, GIRO, Salary, etc.)
- Extracts reference numbers, card details, and transaction IDs
- Formats descriptions for better readability
- Assigns appropriate categories based on transaction details
-
addSummaryRow: Adds totals for withdrawals and deposits- Calculates total amounts
- Provides category-based subtotals
- Adds a summary row at the end of the data
The script automatically categorizes transactions into the following types:
- Dining: Restaurants, cafes, food outlets, bakeries
- Groceries: Supermarkets, grocery stores, NTUC FairPrice, Cold Storage
- Transport: Grab, taxis, MRT, bus services, Gojek
- Shopping: Amazon, Lazada, Shopee, retail stores
- Bills: Utility bills, service payments
- Telecommunications: Phone bills, internet services
- Utilities: Power, water, gas bills
- Housing: Rent, property-related payments
- Insurance: Insurance premiums and payments
- Salary: Income from employment
- Investment: Securities, trading, investment platforms
- Investment Income: Dividends, interest from investments
- Cash Withdrawal: ATM withdrawals
- Fees: Bank fees, service charges
- Transfer: General fund transfers
- Income: Other income sources
- Expense: General expenses
The script is optimized to handle different types of transactions:
- Extracts merchant name and location
- Preserves card number information
- Captures transaction date
- Categorizes based on merchant information
- Captures recipient name (TO: field)
- Preserves transfer numbers
- Extracts reference information
- Categorizes based on recipient details
- Extracts company name information
- Preserves payment details and references
- Formats information in a clear, readable structure
- Categorizes based on company name and payment details
- Preserves sender information (FROM: field)
- Captures any reference numbers
- Maintains other transaction-specific details
- Assigns appropriate categories based on available information
If you're using a different bank's statement format, you may need to customize these functions to match your specific format. The script includes an alternative parser (processStatementDataAlternative) that can be modified for other bank statement formats.
You can also customize the categorization logic in the cleanupDescription function to match your specific needs and add additional categories.
If the script doesn't extract data correctly:
- Check the console output for any errors
- Examine the
extracted-text.txtfile to understand how your PDF content is structured - Modify the parsing functions to better match your bank statement format
ISC