TL/DR: Any way to work out if known numbers between a known start and ending figure should be positive or negative numbers?
I am developing an application in PHP which can import and read PDFs. The PDFs are financial ones such as bank statements with records of transactions in and out of a bank account. I only have PDFs to work with, no other formats such as CSV unfortunately.
I convert the PDF to HTML using pdftohtml and start parsing the data, the intended end result is an array of transactions. So far I have it working smoothly collecting dates, descriptions and balance. Converting the XML instead doesn’t help.
There are other pieces of transcriptional data such as debit or credit amounts. In the PDF, the credit amount is in one column and the debit amount is in another column so it is quite clear in the PDF. However, when converted to HTML, the formatting is lost and therefor I don’t know if the amount was a credit or debit amount.
So, my question is, given a starting balance and an ending balance and several known figures in between, is it possible for a programme to work out if those known figures in between are credit or debit amounts?
I imagine there could potentially be several combinations of those known values to reach the ending balance so I’d like to apply a formula to return the correct credit/debit sequence only if its the only possible solution. If there are several ways of adding/subtracting the known values to reach the end balance, I can ask the user to look at it manually but I’d like to keep this to a minimum if possible.
Possible to do, do you think? Thank you in advance for any help.
2
If there are only a few values between the starting and the ending figure, you could use a brute force algorithm (try out all the combinations of pluses and minuses). I doubt there’s a much more efficient way of doing this, since it’s not enough to just find one solution – you need to check if it’s the only solution.
You could probably use some tricks to make the whole process a bit faster, but that still won’t help you if you have a lot of numbers in between.
That solution, however, seems inelegant… Maybe you should concentrate on finding a way of preserving the debit/credit information when converting data from PDF to HTML. What do your output files look like? Isn’t there a pattern (like “debit values are in odd positions and credit values are in even positions” or something similar)?
11
I can’t see how that would be possible. Consider this:
Starting balance $100
$10 credit
$5 debit
$5 debit
Closing balance $100
And this:
Starting balance $100
$10 debit
$5 credit
$5 credit
Closing balance $100
How could you distinguish between those two cases?
1