PHP code example of eugenefvdm / fnb-pdf-statement-parser
1. Go to this page and download the library: Download eugenefvdm/fnb-pdf-statement-parser library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
eugenefvdm / fnb-pdf-statement-parser example snippets
use FnbStatementParser\FnbStatementParser;
$parser = new FnbStatementParser();
$result = $parser->process('/path/to/statement.pdf');
// Access transactions, validation, metadata
$transactions = $result->transactions;
$validation = $result->validation;
$csv = $result->toCsv();
nbStatementParser\FnbStatementParser;
$pdfPath = __DIR__ . '/path/to/statement.pdf';
$parser = new FnbStatementParser();
$result = $parser->process($pdfPath);
echo "Total transactions: " . count($result->transactions) . "\n";
echo "Expected credits: " . ($result->validation->expectedCreditCount ?? 'N/A') . "\n";
echo "Actual credits: " . $result->validation->actualCreditCount . "\n";
echo "Expected debits: " . ($result->validation->expectedDebitCount ?? 'N/A') . "\n";
echo "Actual debits: " . $result->validation->actualDebitCount . "\n";
// Show credit transactions
$credits = array_filter($result->transactions, fn($t) => $t->type === 'credit');
foreach ($credits as $credit) {
echo $credit->date->format('d M Y') . " - " . $credit->description . " - " . number_format($credit->amount, 2) . "\n";
}
$result = $parser->process($pdfPath);
file_put_contents('extracted_text.txt', $result->extractedText);
// Then search for specific transactions
$lines = explode("\n", $result->extractedText);
foreach ($lines as $lineNum => $line) {
if (preg_match('/pattern/i', $line)) {
echo "Line " . ($lineNum + 1) . ": " . $line . "\n";
}
}
bash
php -r "