PDF Xpress for .NET - User Guide > How To > Work with Security |
PDF Xpress™ supports working with Security for Documents.
|
The following is an example in which a secure PDF Document is opened, and the Security Settings are queried (e.g., Permissions, EncryptMethod, User Password, Owner Password) by calling the GetSecurity() method.
C# |
Copy Code
|
---|---|
using Accusoft.PdfXpressSdk; using System; namespace Security { class Program { static void Main(string[] args) { using (PdfXpress pdf = new PdfXpress()) { pdf.Initialize(); using (Document doc = new Document(pdf, "document.pdf", "user")) { using (Security security = doc.GetSecurity(String.Empty)) { PermissionStatus commentingAllowed = security.Commenting; PermissionStatus changingTheDocumentAllowed = security.ChangingTheDocument; EncryptMethod encryptMethod = security.EncryptMethod; } } } } } } |
The following is an example in which a secure PDF Document is opened, and the Security Settings are queried by calling the GetSecurity() method and are then modified.
By passing the correct Owner Password as the parameter of the GetSecurity() method, the Security Settings obtained can be modified.
C# |
Copy Code
|
---|---|
using Accusoft.PdfXpressSdk; using System; namespace Security { class Program { static void Main(string[] args) { using (PdfXpress pdf = new PdfXpress()) { pdf.Initialize(); using (Document doc = new Document(pdf, "document.pdf", "user")) { using (Security security = doc.GetSecurity("owner")) { security.ContentCopying = PermissionStatus.NotAllowed; security.UserPassword = "accusoft"; security.OwnerPassword = "pdf"; SaveOptions saveOptions = new SaveOptions(); saveOptions.Linearized = true; saveOptions.Overwrite = true; saveOptions.Filename = "saved.pdf"; doc.Save(saveOptions); } } } } } } |
The following is an example in which a secure PDF Document is opened and the Security Settings are removed by calling the RemoveSecurity() method.
By passing the correct Owner Password as the parameter of the GetSecurity() method, the Security Settings obtained can be modified.
C# |
Copy Code
|
---|---|
using Accusoft.PdfXpressSdk; using System; namespace Security { class Program { static void Main(string[] args) { using (PdfXpress pdf = new PdfXpress()) { pdf.Initialize(); using (Document doc = new Document(pdf, "document.pdf", "user")) { using (Security security = doc.GetSecurity("owner")) { doc.RemoveSecurity(); SaveOptions saveOptions = new SaveOptions(); saveOptions.Linearized = true; saveOptions.Overwrite = true; saveOptions.Filename = "saved.pdf"; doc.Save(saveOptions); } } } } } } |
The following is an example in which a non-secure PDF document is opened and Security Settings are added by calling the AddSecurity() method.
An Owner Password must be specified when adding Security to a Document. |
C# |
Copy Code
|
---|---|
using Accusoft.PdfXpressSdk; using System; namespace Security { class Program { static void Main(string[] args) { using (PdfXpress pdf = new PdfXpress()) { pdf.Initialize(); using (Document doc = new Document(pdf, "document.pdf")) { using (Security security = new Security()) { security.OwnerPassword = "owner"; security.HighResolutionPrinting = PermissionStatus.NotAllowed; doc.AddSecurity(security); SaveOptions saveOptions = new SaveOptions(); saveOptions.Linearized = true; saveOptions.Overwrite = true; saveOptions.Filename = "saved.pdf"; doc.Save(saveOptions); } } } } } } |