简体   繁体   中英

Resize multiple single PDF per command line

We have around 100 PDFs in a folder with different page sizes (ie 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:

  1. Your Ghostscript installation is not a recent version.
  2. Your input PDF files use subsetted fonts where the 'unique' prefix (such as 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM