We have around 100 PDFs in a folder with different page sizes (i.e. A4, weirder ones) but all with the A4 length to width ratio. Now we need to resize all to the same size, namely A4.
At the moment we have Sejda in use for merging some PDFs per batch file. Therefore we would prefer a solution per batch file again.
In this question they suggested among other solutions to use PDFtk or PDF split and merge, but they don't seem to offer this functionality. Any other approaches or hints?
You can try to use Ghostscript for this. The following command will resize each individual PDF to A4:
for input in *.pdf ; do
gs \
-o A4-resized-${input} \
-sDEVICE=pdfwrite \
-dPDFFitPage \
-g5950x8420 \
-dPDFSETTINGS=/prepress \
${input}
done
This command will create a merged PDF from all input files, resizing each page in the process:
gs \
-o A4-resized-${input} \
-sDEVICE=pdfwrite \
-dPDFFitPage \
-g5950x8420 \
-dPDFSETTINGS=/prepress \
*.pdf
If the shell wildcard *.pdf
does not sort the pages to your liking, you have to do it by yourself:
[...gs-cmd...] input1.pdf input2.pdf input3.pdf [input4.pdf ...]
Caveats: The second option (merging and resizing the individual PDFs) may cause problems with fonts in the merged PDF in these cases:
XAGTRU+
) to the font name is not unique at all but rather predictable. OpenOffice/LibreOffice and other PDF generators are known to always start their prefixes (predictably) as BAAAAA+
, CAAAAA+
, DAAAAA+
. This leads to multiple instances of BAAAAA+Arial
subsetted fonts injected by the input PDFs which are not unique but different and still use the same name.