Last active
November 12, 2023 20:23
-
-
Save dwallraff/cd6cedd3d89d9da446165fef8aaffb54 to your computer and use it in GitHub Desktop.
Convert jpeg's to pdf/a with OCR and encrypts them
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
#! /usr/bin/env bash | |
#-- Dave Wallraff | |
# First things first, I'm the realest... | |
### convert scans to OCR'd PDF/A, and encrypt them | |
# curl -sL dwallraff.com/scanned | bash | |
# wrap in a function for curl|bash | |
do_stuff() { | |
# Check if op is installed | |
if [ ! "$(command -v op)" ]; then | |
echo "The op cli is not installed. Aborting..." | |
exit 1 | |
fi | |
# Check if op is logged in | |
if ! op whoami > /dev/null 2>&1; then | |
echo "Not logged into 1password" | |
echo "Please run: eval \"\$(op account add --account my.1password.comn --email [email protected] --address my.1password.com --signin)\"" | |
exit 1 | |
fi | |
# Needed vars | |
TODAY=$(date "+%Y%m%d") | |
# Loop over jpegs, convert to pdf, and encrypt | |
for i in *.jpeg; do | |
echo "Converting $i..." | |
img2pdf "$i" | ocrmypdf -j1 -q --output-type pdfa --pdfa-image-compression jpeg --optimize 3 --deskew --clean - "$TODAY"_"${i%%.*}".pdf | |
exec 3<<<"$(op item get encrypted_tar_password --format json | jq -r '.fields[] | select(.id=="password") | .value')" | |
gpg --batch --cipher-algo AES256 --passphrase-fd 3 --symmetric --output "$TODAY"_"${i%%.*}".pdf.enc "$TODAY"_"${i%%.*}".pdf | |
done | |
} | |
do_stuff |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment