Merge multiple jpg into single pdf in Linux

后端 未结 6 1948
南旧
南旧 2021-01-30 02:25

I used the following command to convert and merge all the jpg files in a directory to a single pdf file.

convert *.jpg file.pdf

Th

6条回答
  •  忘了有多久
    2021-01-30 02:43

    Mixing first idea with their reply, I think this code maybe satisfactory

    jpgs2pdf.sh
    
    #!/bin/bash
    
    cd $1
    FILES=$( find . -type f -name "*jpg" | cut -d/ -f 2)
    mkdir temp > /dev/null
    cd temp
    
    for file in $FILES; do
     BASE=$(echo $file | sed 's/.jpg//g');
     convert ../$BASE.jpg $BASE.pdf;
    done &&
    
    pdftk `ls -v *pdf` cat output ../`basename $1`.pdf
    cd ..
    rm -rf temp
    

提交回复
热议问题