Skip to content

Instantly share code, notes, and snippets.

@JohnAZoidberg
Created April 17, 2020 21:45
Show Gist options
  • Save JohnAZoidberg/2ec83c2319f9a10decd8fc6ee886ef3c to your computer and use it in GitHub Desktop.
Save JohnAZoidberg/2ec83c2319f9a10decd8fc6ee886ef3c to your computer and use it in GitHub Desktop.
Split a scanned PDF at a separator page with a QR code
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p zbar poppler_utils
# Separate PDF
pdfseparate scanned.pdf 'page-%02d.pdf'
# Combine
pdfs=""
combined=0
names=(
"Mietvertrag"
"Arbeitsvertrag"
"Meldebestaetigung"
)
for f in page*; do
if zbarimg "$f" 2> /dev/null | grep -q "QR-Code:This is Daniels separator page"; then
pdfunite $pdfs "${names[combined]}.pdf"
combined=$((combined+1))
pdfs=""
else
pdfs="$pdfs $f"
fi
done
pdfunite $pdfs "${names[combined]}.pdf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment