PDA

Click to See Complete Forum and Search --> : [RESOLVED] Paper size fitting algorithm ?


wayneh
Aug 28th, 2007, 02:15 PM
I'm trying to find a way to automatically determine the best paper size to print a file onto.

Assume you have a list of 2 dimensional paper sizes.
Then given a 2 dimensional image size, find the best paper fit, where "best"
means the smallest paper the image can fit on. Rotation is acceptable - meaning the dimensions can be swapped x <-> y if they give the best fit.
So, given an image 5x9, a page that is 10x5 is acceptable if no other fit is better.

Also assume the list may contain repeats and swapped dimensions.

For example:
image: 209 x 280

available sizes:
1: 215 x 279
2: 279 x 431
3: 431 x 279
4: 215 x 355
5: 184 x 266
6: 297 x 420
7: 210 x 297
8: 165 x 131
9: 190 x 254

In this scenario 2,3, 4, 6 and 7 all would work, but 7 is the "best fit".
1, 5, 8 and 9 are too small.

Does anyone know of an algorithm to calculate this?

Thanks.

zaza
Aug 28th, 2007, 02:20 PM
Sounds pretty straightforward. Just loop through all available sizes. Check both dimensions against both image dimensions. If one image dimension is bigger than both paper dimensions, then the paper is too small. If both dimensions fit, calculate the remaining area. Check the area against the current minimum area; if less then this is your new "best fit".

wayneh
Aug 28th, 2007, 02:52 PM
zaza-
Thanks - I was actually trying that and I thought I had it wrong.
But I went back and checked, and it seems I was not storing the "smallest" properly.
I think it's working now - thanks for the prodding...

zaza
Aug 28th, 2007, 03:23 PM
Jolly good. Don't forget to mark the thread Resolved.