ImageMagick | Convert images to A4 PDF
mouse 537 · person cloud · link
Last update
2017-08-14
2017
08-14
« — »
1
2
3
4
5
6
convert *.jpg \
  -compress jpeg -quality 75 \
  -resize 1240x1754 -extent 1240x1754 \
  -gravity center -units PixelsPerInch \
  -density 150x150 \
  out.pdf

A4 measures 210x297mm / 8.27x11.69in / 595x842pt.

At 150ppi the image needs to be 1240x1754px.

At 300ppi the image needs to be 2480x3508px.

Hint: to crop the image to adapt to the A4 aspect ratio:

1
2
# crop bottom at 83%
for i in *.jpg; do convert $i -crop "x83%" -delete 1 out/$i; done




Here are the commands for my scanner (Canon Lide35):

1
2
3
4
5
6
7
8
9
# scanimage -d ... --resolution 300 --mode Gray | convert - xxx.jpg

for i in *.jpg; do
  convert "$i" -crop "96.67%x99.7%" -delete 1-3 \
    -compress jpeg -quality 75 -resize 1240x1754 -extent 1240x1754 \
    -gravity center -units PixelsPerInch -density 150x150 "resized/$i"
done

convert resized/*.jpg document.pdf

Source: StackOverflow, PrePressure