Skip to content

Commit

Permalink
Merge pull request #5 from datamade/hcg/decrypt
Browse files Browse the repository at this point in the history
Conditionally decrypt PDFs with qpdf
  • Loading branch information
hancush authored Nov 10, 2021
2 parents 6e84626 + 351533d commit 41d62e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM python:3.9-slim
LABEL maintainer "DataMade <[email protected]>"

RUN apt-get update && \
apt-get install -y make libreoffice poppler-utils wget && \
apt-get install -y make libreoffice poppler-utils qpdf wget && \
rm -rf /var/lib/apt/lists/*

RUN mkdir /app
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
SHELL := /bin/bash
ATTACHMENTS := $(shell python scripts/download_attachments.py)

define decrypt
$(shell pdfinfo $(1) | grep "Encrypted: yes" > /dev/null 2>&1 &&
qpdf --decrypt $(1) --replace-input)
endef

clean :
find attachments -type f -not -name .gitkeep -delete
find merged -type f -not -name .gitkeep -delete
Expand All @@ -9,6 +14,7 @@ upload_% : merged/%.pdf
aws s3 cp $< s3://$$S3_BUCKET_NAME --acl public-read

merged/%.pdf : $(addsuffix .pdf,$(basename $(ATTACHMENTS)))
$(foreach attachment,$^,$(call decrypt,$(attachment)))
pdfunite $^ $@

attachments/%.pdf : attachments/%.xlsx
Expand Down

0 comments on commit 41d62e2

Please sign in to comment.