Skip to content

Instantly share code, notes, and snippets.

@seppo0010
Last active February 25, 2023 00:50
Show Gist options
  • Save seppo0010/0802b7bc3ffc0d9ffda8a11714c5f793 to your computer and use it in GitHub Desktop.
Save seppo0010/0802b7bc3ffc0d9ffda8a11714c5f793 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -Eeux
f=493393291-Borda-Manual-de-Contratos-2020.pdf
prev_page=0
prev_title=""
while read line; do
this_page=$(echo $line | awk '-F:' '{print $1}')
this_title=$(echo $line | awk '-F:' '{print $2}' |xargs)
target="${f/.pdf/} - $prev_title.pdf"
if [ "$prev_page" -gt 0 ] && [ ! -f "$target" ]; then
pdfjam "$f" "$prev_page-$this_page" -o "$target"
fi
prev_page="$this_page"
prev_title="$this_title"
done < <(pdfgrep -n 'CAPÍTULO' "$f")
target="${f/.pdf/} - $prev_title.pdf"
if [ "$prev_page" -gt 0 ] && [ ! -f "$target" ]; then
pdfjam "$f" "$prev_page-" -o "$target"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment