cross-posted from: https://libretechni.ca/post/1944375

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.
  • 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.

  • sin_free_for_00_days@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 hours ago

    Without knowing a dedicated app, this is how I think I would go about it:

    1. Batch scan with a feeder into individual documents
    2. Run all the images through magick -trim probably with some fuzz option as well
    3. Might as well run some OCR on all the documents as well to embed the text ocrmypdf
    4. I’d imagine for receipts you’d want to tag or label them, so do that as well, which seems like it would have to be a little hands on. Maybe make up a naming scheme, Date-Expense Category-Location-Notes (whatever works)
    5. Sort by width, throw them in a Latex document resizing to fit 2-column width using minipage or another option, then maybe 1-column above a certain size.

    It doesn’t seem like it would take much more than a few hours at most to script up something that could do that. You could probably easily add a table of contents with the titles or info from the images (from step 4) as well to make it organized. Once set up, it shouldn’t take more than a couple of minutes to go through a month or more of receipts. File the receipts by month (or quarter or year), update the document monthly (or however often needed), and you’d be pretty well organized.

    Steps 1-3 are basically one-liners. Step 4 would be a couple lines of bash, and step 5 would be a handful of lines of bash. Really it’s not much.