#!/bin/bash

[[ -n "$DEBUG" ]] && set -x
set -euo pipefail

pdfinfo "${DOCUMENT_WORKING_PATH}" | grep -q "Encrypted:"

if pdfinfo "${DOCUMENT_WORKING_PATH}" | grep -q "Encrypted:       yes"
then
    qpdf --replace-input --decrypt "${DOCUMENT_WORKING_PATH}"
fi
