password protect pdf files created using pisa

Question:

I’m converting a html file into pdf using python pisa module. I need to password protect it. I searched everywhere in pisa module and couldn’t find a solution for it. Is there anyway to password protect it using python?

The constraint is I want keep my file in html format. On demand basis, I want to convert it into pdf file and password protect it. I don’t want to use reportlab module.

Asked By: thavan

||

Answers:

You can with pyPdf which is optional for pisa but has an encryption method:

A Pure-Python library built as a PDF toolkit. It is capable of:

extracting document information (title, author, …), splitting
documents page by page, merging documents page by page, cropping
pages, merging multiple pages into a single page, encrypting and
decrypting PDF files
.

Answered By: Hedde van der Heide

you could make use of encrypt argument of pisa.CreatePDF

pdf = pisa.CreatePDF(html, encrypt='password', dest=response)
Answered By: stranger