Watermarking and encrypting a PDF
PDF files have some interesting security measures to limit the distribution of a document. We can encrypt the content, requiring users to input a password in order to be able to read it. We'll also see how to add a watermark to label the document clearly as not for public distribution and, if leaked, to know its origin.
Getting ready
We'll use the pdf2image
module to transform PDF documents to PIL images. Pillow
is a prerequisite. We'll also use PyPDF2
:
$ echo "pdf2image==1.11.0" >> requirements.txt
$ echo "Pillow==7.0.0" >> requirements.txt
$ echo "PyPDF2==1.26.0" >> requirements.txt
$ pip install -r requirements.txt
For pdf2image
to work properly, it needs to install pdftoppm
, so check here for instructions on how to install it for different platforms: https://github.com/Belval/pdf2image#.
We also need a PDF file to watermark and encrypt. We'll use a report...