I need some sort of an algorithm, that would try to find free space on a specified page of a PDF.
The space I’m looking for is a square 100×100 pixel large. I would like to start searching from the bottom right, move further left in a row, and then gradually move up rows, until I either find a suitable space (free-space/white-space), or return error, that there is no free space.
Anyone aware of such a possibility in Android? And if not, how could I implement it?
Edit
I have been doing quite a bit of research on this lately, and am I right in assuming, that finding a free spot is not possible, until the document is rendered? Because if I’m getting it, right, every vector and every object should be put in it’s place, just to find the free spaces? Meaning, the places which no vectors intersect?
You definitely need to render the PDF. You can use something like poppler, and then search for white regions. Here is an open source Android app using poppler that you could modify/use as inspiration:
http://code.google.com/p/apdfviewer/
Once you have the rendered PDF, you can use something like the Boyer-Moore string search algorithm to find space. I.e. in 1D you are trying to find the string “…….” in “+++…++…..+………..” where . = white and + = not white.
In 2D it will be more complicated, the most efficient thing I can think of is something like this:
If you see what I mean… something like this:
Hmm I can see several things wrong with that code already.. but hopefully you get the idea. I expect that algorithm exists already but I don’t know the name for it unfortunately.