An opening balance of $2,450.00, one $1,200.05 deposit, and three withdrawals of $86.24, $86.24, and $12.34 must close at $3,465.23. The identical withdrawals look like a duplicate until you check their distinct bank references. Dropping either row makes the export wrong by $86.24.
Give the PDF extractor a narrow job
Extract one account and currency at a time. Read the opening and closing figures from the statement summary and keep them separate from the transaction table. For each row, retain the posted date, description, signed amount, bank reference if printed, and source location. Join wrapped descriptions before parsing money. Skip repeated table headers and carried-forward balances. On scanned statements, retain page coordinates so a reviewer can check signs, decimal points, and low-confidence digits against the image.
Normalize a deposit to positive and a withdrawal to negative for a checking account. Convert a decimal string directly into cents and reject ambiguous formats at the normalization boundary. For example, map a printed withdrawal of (86.24) to -86.24 in your adapter. Reconciliation then checks opening cents + sum of signed rows = closing cents. A matching total can still hide offsetting errors, so compare row counts and intermediate balances where the statement provides them.
Fail before writing either CSV
An account-scoped bank reference can identify a repeated row. Without a reference, the date, normalized description, and signed amount form a weaker fingerprint. Treat a weak collision as a review item. Preserve rows with distinct references even when the fingerprints match. Keep PDF page and row location for review, since a duplicate extracted across a page break can have two different locations.
Save the following as statement.mts and run node statement.mts with Node.js 24. The built-in fixture represents normalized PDF rows. To try a normalized statement from your own extractor, pass its JSON as the first argument using the same fields and string amounts as the fixture. Node.js TypeScript support
import assert from "node:assert/strict";
import { readFile, writeFile } from "node:fs/promises";
type BankRow = {
date: string;
description: string;
amount: string;
reference?: string;
source: string;
};
type Statement = { opening: string; closing: string; rows: BankRow[] };
type CheckedRow = BankRow & { amountCents: bigint };
function parseCents(text: string): bigint {
assert.equal(typeof text, "string", "Supply normalized decimal strings");
const match = /^(-?)(\d+)\.(\d{2})$/.exec(text);
if (!match) throw new Error(`Expected a decimal with two cents digits: ${text}`);
const magnitude = BigInt(match[2]) * 100n + BigInt(match[3]);
return match[1] ? -magnitude : magnitude;
}
function decimal(cents: bigint): string {
const absolute = cents < 0n ? -cents : cents;
return `${cents < 0n ? "-" : ""}${absolute / 100n}.${String(absolute % 100n).padStart(2, "0")}`;
}
function uploadDate(iso: string): string {
const date = new Date(`${iso}T00:00:00Z`);
if (!/^\d{4}-\d{2}-\d{2}$/.test(iso) || !Number.isFinite(date.getTime())
|| date.toISOString().slice(0, 10) !== iso) {
throw new Error(`Invalid posted date: ${iso}`);
}
const [year, month, day] = iso.split("-");
return `${day}/${month}/${year}`;
}
function reconcile(statement: Statement): CheckedRow[] {
const references = new Map<string, string>();
const fingerprints = new Map<string, { source: string; hasReference: boolean }>();
let computedClosing = parseCents(statement.opening);
const checked = statement.rows.map((row) => {
uploadDate(row.date);
const amountCents = parseCents(row.amount);
const description = row.description.trim().replace(/\s+/gu, " ");
assert(description, `Empty description at ${row.source}`);
const reference = row.reference?.trim();
if (reference) {
const first = references.get(reference);
if (first !== undefined) throw new Error(`Repeated bank reference at ${first} and ${row.source}`);
references.set(reference, row.source);
}
const fingerprint = JSON.stringify([row.date, description.toLowerCase(), amountCents.toString()]);
const earlier = fingerprints.get(fingerprint);
if (earlier && (!reference || !earlier.hasReference)) {
throw new Error(`Possible duplicate at ${earlier.source} and ${row.source}. Review the PDF.`);
}
fingerprints.set(fingerprint, { source: row.source, hasReference: Boolean(reference) });
computedClosing += amountCents;
return { ...row, description, amountCents };
});
const discrepancy = computedClosing - parseCents(statement.closing);
if (discrepancy !== 0n) {
throw new Error(`Computed closing ${decimal(computedClosing)} differs by ${decimal(discrepancy)}`);
}
return checked;
}
function csvField(text: string): string {
return /[",\r\n]/.test(text) ? '"' + text.replace(/"/g, '""') + '"' : text;
}
function quickBooksCsv(rows: CheckedRow[], columns: 3 | 4): string {
const header = columns === 3
? ["Date", "Description", "Amount"]
: ["Date", "Description", "Credit", "Debit"];
const records = rows.map(({ date, description, amountCents }) => {
const cells = [uploadDate(date), description];
if (columns === 3) cells.push(amountCents === 0n ? "" : decimal(amountCents));
else cells.push(amountCents < 0n ? decimal(-amountCents) : "",
amountCents > 0n ? decimal(amountCents) : "");
return cells;
});
return [header, ...records].map((row) => row.map(csvField).join(",")).join("\r\n") + "\r\n";
}
const fixture: Statement = {
opening: "2450.00",
closing: "3465.23",
rows: [
{ date: "2026-11-03", description: "Client deposit", amount: "1200.05", reference: "DEP-A", source: "p1:r1" },
{ date: "2026-11-04", description: "Harbor Market, East", amount: "-86.24", reference: "CARD-A", source: "p1:r2" },
{ date: "2026-11-04", description: "Harbor Market, East", amount: "-86.24", reference: "CARD-B", source: "p2:r1" },
{ date: "2026-11-06", description: "Service fee", amount: "-12.34", source: "p2:r2" },
],
};
const input = process.argv[2];
const statement: Statement = input ? JSON.parse(await readFile(input, "utf8")) : fixture;
const checked = reconcile(statement);
const three = quickBooksCsv(checked, 3);
const four = quickBooksCsv(checked, 4);
if (!input) {
assert.throws(() => reconcile({ ...fixture, closing: "3465.24" }), /differs by -0.01/);
assert.throws(() => reconcile({ ...fixture, rows: [...fixture.rows, fixture.rows[1]] }), /Repeated bank reference/);
const lastRow = fixture.rows.at(-1)!;
assert.throws(() => reconcile({
...fixture, rows: [...fixture.rows, { ...lastRow, source: "p3:r1" }],
}), /Possible duplicate/);
assert.equal(checked.length, 4);
assert(three.includes('04/11/2026,"Harbor Market, East",-86.24\r\n'));
assert(four.includes("03/11/2026,Client deposit,,1200.05\r\n"));
assert(four.includes('04/11/2026,"Harbor Market, East",86.24,\r\n'));
}
await writeFile("quickbooks-3-column.csv", three);
await writeFile("quickbooks-4-column.csv", four);
console.log(`Reconciled ${checked.length} rows at closing ${statement.closing}. Wrote both CSV layouts.`);
Verify the import mapping
The three-column export uses a signed Amount. The four-column export follows Intuit’s U.S. example, which puts a positive magnitude in Credit for a payment or Debit for a deposit and leaves the other cell blank. Map the actual money-spent and money-received fields in the upload preview, choose the day/month/year format, and verify one deposit and one withdrawal before importing one of the files. Check the target account for transactions already covered by its bank feed. Intuit CSV formats · Intuit manual upload walkthrough
StatementPack is published by the team behind this article. It converts bank statement PDFs into reconciled QuickBooks CSV and XLSX for review. StatementPack
AI disclosure. This article was generated with AI.
Top comments (0)