I am creating pdf on fly and adding header/footer , Stamp. At last encrypting (with password) the file.
But when I try to open it, it is not password protected
Is that not supported or I am doing it wrong way?
My sample code :
Document PdfDocument;
PdfFileSecurity fileSecurity;
PdfFileStamp fileStamp
PdfDocument = new Document();
PdfDocument.Pages.Add(); // Adding empty page.
// Adding Header
TextStamp textStamp = new TextStamp(“Test”);
textStamp.TopMargin = (double)10;
textStamp.VerticalAlignment = VerticalAlignment.Top;
page.AddStamp(textStamp);
fileStamp.AddStamp(stamp);
//Adding Stamp
fileStamp = new PdfFileStamp(PdfDocument);
Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
string stampText = “My Stamp”;
stamp.BindLogo(new FormattedText(stampText, forColors, backColors, Aspose.Pdf.Facades.FontStyle.Helvetica, EncodingType.Winansi, true, size));
// Encrypting with password
DocumentPrivilege privilege = DocumentPrivilege.ForbidAll
string userpassword = “abcd”;
string masterpassword= “”;
fileSecurity = new PdfFileSecurity(PdfDocument);
fileSecurity.EncryptFile(userpassword, masterpassword, privilege, KeySize.x256, Algorithm.AES);
//Saving
PdfDocument.Save(@“C:\Users\ankur.patel\Desktop\Encrypt.pdf”);
//Disposing
if (fileSecurity != null){ fileSecurity.Dispose();}
if (fileStamp != null){ fileStamp.Dispose();}
if (PdfDocument != null){ PdfDocument.Dispose(); }
Regards,
Ankur