PdfDocumentSource allows you to set password for protecting your PDF document. It allows you to create a password protected PDF using the PdfSecurityOptions class from C1.Win.Document.Export namespace. The PdfSecurityOptions class lets you set a password to open the PDF document using the UserPassword property.
Let's say the user wants to generate a password-protected PDF document at the click of a button. For this, you can follow the steps below:
Load the PDF document using the LoadFromFile method of PdfDocumentSource component:
C# |
Copy Code
|
---|---|
private void Form1_Load(object sender, EventArgs e) { c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf"); } |
Create an object of PDFFilter class to access the PDF document using the FileName property and set the password using the PdfSecurityOptions.UserPassword property. Then, export the PDF with password using the Export method.
C# |
Copy Code
|
---|---|
private void pwBtn_Click(object sender, EventArgs e) { //export pdf with password var filter = new PdfFilter(); filter.FileName = @"..\..\Password.pdf"; filter.PdfSecurityOptions.UserPassword = "pass1234"; c1PdfDocumentSource1.Export(filter); } |