Over the holiday I read an interesting question asking how to find numbers within a specific range on a PDF page. This set me thinking…
Our perception is very much effected by the tools we generally use. If we spend our lives in spreadsheets, we think of pages as lots of cells which can have a type. If we use XML, we expect everything to be nested and tagged.
The PDF format is very much an output format so it looks great but there is often little or no metadata. There are no numbers, strings or other object types data. It is all text on the page. This does not mean we cannot search for specific types, but we have to alter our thinking. So here is how I would find and values within a number range on a PDF page.
1. Convert the PDF page text data into a wordlist. This will give you all the words and their position on the page. If you want to use JPedal, see PDF to text as a word list.
2. Ignore all values which are clearly not numbers (numbers can only contain characters 0-9, comma, decimal and plus or minus).
3. This will give us a set of possible values and locations. We can then convert them to numbers with Integer.parseint(str) and see if they match our range.
So it is perfectly possible to find a numeric range of values on a PDF page although not as easy as in Excel. Or do you have a better solution?
Latest posts by Mark Stephens (see all)
- How we are improving our code quality with IDEA in 2018 - March 7, 2018
- How we are improving our code quality with NetBeans in 2018 - March 1, 2018
- 3 ways that the European Union is changing the way Companies write software in 2018 - January 31, 2018
- IDRsolutions product range update for 2018 - January 22, 2018
- 4 ways Companies can make remote working successful - December 21, 2017