If you scan paper receipts which you will then later submit copies of (either to your accountant, to a tax auditor, or to your employer), it is often useful to organize them on a PDF or to print them.
Today’s FOSS tools leave a lot to be desired. We have:
- ImageMagick’s montage app, which lacks a smart rectangle-fitting algo. The user must specify which images to tile in what order. Not even sure it’s sophisticated enough to not overlap images after the first row when different dimensioned images are involved.
- LaTeX is manual labor intensive. You must micromanage the orientation and position of images.
- Arranged by hand when scanning: probably even more manually intensive than LaTeX because it requires a steady hand to precisely place the images.
Human limitations will often likely have some paper waste due to inefficient placement. A clever algorithm could determine orientation and placement of each receipt to optimise minimisation of whitespace, thus wasting less paper.
A receipt-specific montage algo could detect the font size of each receipt and either shrink or enlarge depending on user-supplied constraints. The goal should be as few A4, A3, or US letter pages as possible, but then enlarge receipts to make better use of the available page space.
In principle, someone with a big brain creates an algorithm distributed as a library. Then ideally there would be an app that uses the library to generate LaTeX code. There could also be an enhancement to ImageMagick’s montage app to do the same.
Rectangle Repacking
After the rectangle packing app is created, it would then be useful to have an app that does the opposite. We arbitrarily put many receipts on the glass for scanning. Some receipts might not relate to others with respect to who it is presented to. A GUI app would accommodate drawing many boxes to mark the boundaries of each receipt and give a way to assign a filename to each box and write the files. Then any selection of resulting files could be fed into the rectangle-packing app. ATM we have to use GIMP to crop a single box, write the file, then reload the original image and repeat for each receipt, taking care to remember what was already cropped.
Rectangle packing is well-trodden territory in multiple fields. I’m most familiar with it from gamedev. There’s a library available in stb already, for example: https://github.com/nothings/stb/blob/master/stb_rect_pack.h
Note that the problem itself is in NP, so you’re not likely to get an optimal packing. In general with problems like this you can usually get good enough results with a decent solver if you don’t aim for perfection.
Wikipedia has an article on the problem: https://en.wikipedia.org/wiki/Rectangle_packing
I also stumbled into this blog post while looking up some details about the algorithm mentioned in the stb library – it has some visualizations that you might find interesting: https://www.david-colson.com/2020/03/10/exploring-rect-packing.html
After the rectangle packing app is created, it would then be useful to have an app that does the opposite.
What you’re describing is an image segmentation problem. There may be older, lighter weight approaches to it, but in 2026, personally, I’d just try throwing an open weight vision model at it. Maybe NVIDIA’s Locate Anything, for example: https://huggingface.co/nvidia/LocateAnything-3B
This isn’t a ready-to-use solution for your particular use case, obviously, but most of the pieces of a solution already exist.

