Skip to content

Instantly share code, notes, and snippets.

@jeeger
Created August 30, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeeger/904219de7045b5f99bcd7832594f0931 to your computer and use it in GitHub Desktop.
Save jeeger/904219de7045b5f99bcd7832594f0931 to your computer and use it in GitHub Desktop.
Tile Burda pattern
#!/bin/bash
NUPX="${1%%x*}"
NUPY="${1##*x}"
PAGESTART="${2%%-*}"
PAGEEND="${2##*-}"
FILE="$3"
# TODO: Check file and values.
PAGESIZES="$(pdfinfo -box -f "$PAGESTART" -l "$PAGEEND" "$FILE" | awk '/[0-9]+ size:/ {print $4 "x" $6}')"
PAGESIZEX="${PAGESIZES%%x*}"
PAGESIZEY="${PAGESIZES##*x}"
RANGES=()
STARTPAGES="$(seq $((PAGEEND-NUPX + 1)) -"$NUPX" "$PAGESTART")"
for startpage in $STARTPAGES; do
RANGES+=("$startpage-$((startpage + NUPX - 1))")
done
PDFJAM_RANGES=$(IFS=","; echo "${RANGES[*]}")
LANG=C TOTALSIZE="$(printf "{%.3fpt,%.3fpt}" "$(echo "$NUPX * $PAGESIZEX" | bc)" "$(echo "$NUPY * $PAGESIZEY" | bc)")"
pdfjam --papersize "$TOTALSIZE" --nup "$NUPX"x"$NUPY" --outfile "${FILE%%.pdf}-joined.pdf" -- "$FILE" "$PDFJAM_RANGES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment