Password Protect Pdf...but still have it readable/printable without password

Hello I am trying to figure out how to make my pdf document readable/printable without being promped for the password I currently have the following code:

FileStream newFileStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
outputStream.WriteTo(newFileStream);
Pdf doc = new Pdf(newFileStream);
doc.Security = new Security();
doc.Security.UserPassword = GeneratePassword();
doc.Security.IsContentsModifyingAllowed = false;
doc.Security.IsFormFillingAllowed = false;
doc.Security.IsPrintingAllowed = true;
doc.Security.IsScreenReadersAllowed = true;

But when the file is opened it is still asking for a password and will not let me view the file without it??

Any help would be appreciated.

Thanks,

Statman88

Hello Nick,

Thanks for considering Aspose.

The code snippet that you have provided above will set a password over document and will allow Printing & ScreenReaders option enabled. But every tim you will open it will ask for the password.

And if your requirement is that every time you open the document its displayed without prompting for password and printing option is enabled. For this reason you will have to use another product named Aspose.Pdf.Kit

PdfFileSecurity fileSecurity = new PdfFileSecurity(inputpdf, outputpdf);
fileSecurity.SetPrivilege(UserPassword, OwnerPassword,DocumentPrivilege.ScreenReaders);
PdfFileSecurity fileSecurity = new PdfFileSecurity(inputpdf, outputpdf);
fileSecurity2.SetPrivilege(UserPassword, OwnerPassword, DocumentPrivilege.Print);

InputPdf is the document that was generated by your code. After you run this code, every time you open the document it will not ask for the password. Please correct me incase i have not properly understood requirement. For more information kindly visit Set Privileges on PDF Document. Please use DocumentPrivilege rather than PdfFileSecurity.