Created
October 9, 2019 12:30
-
-
Save etuardu/559d3b76546437b39d07ba7e22998931 to your computer and use it in GitHub Desktop.
Kreas unu pdf-dosieron kun po unu bildo por pagxo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Kreas unu pdf-dosieron kun po unu bildo por pagxo. | |
# | |
# Notu: bildojn oni prenas el dosierujo. | |
# | |
# Por eltiri bildojn el pdf-dosiero eblas uzi "pdfimages", | |
# ekzemple: | |
# | |
# pdfimages -all input.pdf ./imgs/temp | |
# | |
# eltiras en subdosierujon "imgs" la bildojn el | |
# la pdf-dosiero "input.pdf" donante al ili prefikson "temp". | |
# Agordoj: | |
imgfolder="./imgs" # dosierujo kun la bildoj | |
outfile="output.pdf" # la kreota pdf-dosiero | |
dpi="150" | |
page_width="210" # mm, largxeco de la pagxo | |
page_height="210" # mm, alteco de la pagxo | |
margin="10" # mm, margxeno cxe randoj de pagxo | |
# -- | |
mm2px() { | |
# kalkulas pikselojn el milimetroj | |
# uzado: mm2px <dpi> <mm> | |
# liveras: grandecon en pikseloj | |
echo "($1 * $2) / 25.4" | bc | |
} | |
page_width_px="$(mm2px $dpi $page_width)" | |
page_height_px="$(mm2px $dpi $page_height)" | |
margin_px="$(mm2px $dpi $margin)" | |
img_width_px=$(echo "$page_width_px - ($margin_px * 2)" | bc) | |
img_height_px=$(echo "$page_height_px - ($margin_px * 2)" | bc) | |
tempdir="$(mktemp -d)" | |
for f in $imgfolder/*; do | |
convert -gravity center -density $dpi \ | |
-resize "${img_width_px}x${img_height_px}" \ | |
-extent "${page_width_px}x${page_height_px}" \ | |
"$f" "${tempdir}/${f##*/}.pdf" | |
done | |
pdfunite "$tempdir"/*.pdf "$outfile" | |
rm -r "$tempdir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment