Recently I have been selling a lot of my stuff. Simply getting rid of unused or unneeded things - and mostly I’m packing & sending it to other parts of the country by using a package carrier that requires printing labels. The standard drill. But those labels are kinda smallish, you can fit like 4 on single A4 page (it’s like a horizontal strip kid of thing).
Ok so I’m sending 3 packages and I get 3 pdfs to print with huge amount of white space. I don’t own a printer anymore (sold it as well), I need to go photocopy point, technically speaking I could simply go and ask them to print 3 separate documents. But the environment and extra 20 cents - I just couldn’t stand it :P.
None of the free software I have tried (PDF Studio 12, PDF Editor 6, PDFSam and other) offered me option to do what I really wanted - I could crop single page and merge those pages to a single document with few pages (and you can do that as well in build-in MacOS Preview btw) but I couldn’t merge those pages in the end. So after an hour or so I went back to the basics - imagemagick. Here is the final recipe based on various StackOverflow questions :P.
convert -density 300 -trim *.pdf -quality 100 -append output.jpg && convert output.jpg output.pdf && rm output.jpg
What is happening here is: we’re converting all pdfs within given directory to jpgs on the way we’re trimming all the surrounding blank space and stacking each one on top of another. Then simply we convert back stacked jpg to pdf and removing temporary file - not using unix pipes as it will mess up result - I’m guessing it’s related to how imagemagick is handling convert+append for many files - but I’m not really into details here as it does the job ;-).
It seems the simples approach won again 😉