Reputation: 343
Does Rotativa.MVC support pdf encryption with password? I wasn't able to find any reference about it.
Upvotes: 0
Views: 1008
Reputation: 12452
There is no option to add a password in Rotativa.MVC.
You need to generate your pdf via html and add owner password, user password after that.
Basically you will need another piece of software to encrypt that pdf file or to develop that piece of software by yourself.
Using something like: https://github.com/itextsharper/iTextSharp-4.1.6/blob/master/iTextSharp/text/pdf/PdfEncryptor.cs you'll be able to do the following:
Encrypt(PdfReader reader, Stream os, byte[] userPassword, byte[] ownerPassword, int permissions, bool strength128Bits, Hashtable newInfo)
using (var input = new FileStream("rotativa_generated.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
using (var output = new FileStream("rotativa_generated_encrypted.pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
var reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, "userPassword", "ownerPassword", PdfWriter.ALLOW_PRINTING);
}
Users need only userPassword to get access.
Or you can migrate to something like https://github.com/mstamy2/PyPDF2 just for encryption. (free for commercial use as far as i know)
Upvotes: 1