Mass resize of PDF files

Some days ago I faced a situation, where I had to resize ~50 PDF docs from US Letter to A4 format. It was a set of travel orders from Slovenian online service potninalog.si. Their PDF exporter was generating documents in US Letter (which is really strange, since we mostly use A4 in Slovenia), but my printer was refusing to accept those. 

Number of files was quite too big to do it by hand (with Inkscape for example), so I had to find some faster way to do that. Ghostscript and a little bash script around it were an obviuos way:

#!/bin/bash 

for f in `ls *.pdf`; 
  do gs -o ./A4/$f -sDEVICE=pdfwrite -dPDFFitPage -r300x300 -g2483x3510 $f
done

Simple BASH script, that solved my problem (2483x3519 pixels are ~A4 at 300dpi). Now I just needed to move to the right folder and run:

 

lpr *.pdf 

 

Since printer needed some time to process that, I had a great chance to enjoy a beer :).