ComponentOne PDF for .NET
Applying Security and Permissions
Using ComponentOne PDF for .NET > Applying Security and Permissions

By default, anyone can open, copy, print, and edit PDF files. If your PDF documents contain sensitive information, however, you can encrypt them so that only authorized users can access it.

There is a separate password for the owner of the document and for all other users. The user's access can be selectively restricted to allow only certain operations, such as viewing, printing, or editing the document.

PDF for .NET provides a C1PdfDocumentBase.Security property that returns a PdfSecurity object. This object has properties that allow you to specify the owner password (required to change passwords and permissions for the document) and the user password (required to open the document). Additionally, the PdfSecurity object allows you to specify what permissions a regular user should have. For example you may allow users to see the document but not to print or edit it.

To use the PDF for .NET security features, simply set the passwords before you save the document. For example:

To write code in Visual Basic

Visual Basic
Copy Code
 ' Create the document as usual.
CreateDoc()
  ' Set passwords.
_c1pdf.Security.OwnerPassword = "2mds%dffgd"
_c1pdf.Security.UserPassword = "anyone"
_c1pdf.Security.AllowEditAnnotations = False
_c1pdf.Security.AllowEditContent = False
_c1pdf.Security.AllowPrint = False
  ' Save the encrypted document.
_c1pdf.Save("")

To write code in C#

C#
Copy Code
// Create the document as usual.
CreateDoc();
 // Set passwords.
_c1pdf.Security.OwnerPassword = "2mds%dffgd";
_c1pdf.Security.UserPassword = "anyone";
_c1pdf.Security.AllowEditAnnotations = false;
_c1pdf.Security.AllowEditContent = false;
_c1pdf.Security.AllowPrint = false;
 // Save the encrypted document.
_c1pdf.Save(@"c:\reports\secure.pdf");

Note that you can specify permissions and set only the owner password, leaving the user password empty. In this case, anyone will be allowed to open the document, but only the owner will be allowed to change the permissions.

Note also that the encryption scheme used by PDF for .NET is public and is not 100% secure. There are ways to crack encrypted PDF documents. The security provided is adequate to protect your documents from most casual attacks, but if your data is truly sensitive you should not rely on PDF encryption alone.