Class PdfSecurity
Represents the security settings of the PDF document.
Inheritance
Namespace: Syncfusion.Pdf.Security
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfSecurity : Object
Examples
// Creates a new document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
PdfGraphics graphics = page.Graphics;
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
PdfBrush brush = PdfBrushes.Black;
//Document security
PdfSecurity security = document.Security;
//use 128 bits key
security.KeySize = PdfEncryptionKeySize.Key128Bit;
security.OwnerPassword = "syncfusion";
security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FullQualityPrint;
security.UserPassword = "password";
document.Save("Security.pdf");
document.Close(true);
' Creates a new document
Dim document As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = document.Pages.Add()
Dim graphics As PdfGraphics = page.Graphics
Dim font As PdfStandardFont = New PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold)
Dim brush As PdfBrush = PdfBrushes.Black
'Document security
Dim security As PdfSecurity = document.Security
'use 128 bits key
security.KeySize = PdfEncryptionKeySize.Key128Bit
security.OwnerPassword = "syncfusion"
security.Permissions = PdfPermissionsFlags.Print Or PdfPermissionsFlags.FullQualityPrint
security.UserPassword = "password"
document.Save("Security.pdf")
document.Close(True)
Constructors
PdfSecurity()
Initializes a new instance of the PdfSecurity class.
Declaration
public PdfSecurity()
Properties
Algorithm
Gets or sets the type of encryption algorithm used.
Declaration
public PdfEncryptionAlgorithm Algorithm { get; set; }
Property Value
Type |
---|
PdfEncryptionAlgorithm |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
// Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "Syncfusion";
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations | PdfPermissionsFlags.Print;
doc.Security.UserPassword = "123";
doc.Security.Algorithm = PdfEncryptionAlgorithm.AES;
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit
doc.Security.OwnerPassword = "Syncfusion"
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations | PdfPermissionsFlags.Print
doc.Security.UserPassword = "123"
doc.Security.Algorithm = PdfEncryptionAlgorithm.AES
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)
EncryptionOptions
Gets or sets the type of encryption options used.
Declaration
public PdfEncryptionOptions EncryptionOptions { get; set; }
Property Value
Type |
---|
PdfEncryptionOptions |
Examples
PdfDocument document = new PdfDocument();
PdfPage page = document.Pages.Add();
PdfGraphics graphics = page.Graphics;
PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
PdfBrush brush = PdfBrushes.Black;
PdfSecurity security = document.Security;
security.KeySize = PdfEncryptionKeySize.Key128Bit;
security.Algorithm = PdfEncryptionAlgorithm.AES;
security.EncryptionOptions = PdfEncryptionOptions.EncryptAllContents
security.UserPassword = "password";
graphics.DrawString("Encrypted with AES 128bit", font, brush, new PointF(0, 40));
PdfAttachment attachment = new PdfAttachment(@"D:\Hello world.docx");
attachment.ModificationDate = DateTime.Now;
attachment.Description = "Hello world.docx";
attachment.MimeType = "application/txt";
document.Attachments.Add(attachment);
document.Save(@"D:\NormalAttach.pdf");
document.Close(true);
KeySize
Gets or sets the length of the encryption key for encryption.
Declaration
public PdfEncryptionKeySize KeySize { get; set; }
Property Value
Type |
---|
PdfEncryptionKeySize |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
// Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "Syncfusion";
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations;
doc.Security.UserPassword = "123";
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit
doc.Security.OwnerPassword = "Syncfusion"
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations
doc.Security.UserPassword = "123"
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)
See Also
OwnerPassword
Gets or sets the owner password, If the PDF document is password protected you can use the owner password to open the document and change its permissions.
Declaration
public string OwnerPassword { get; set; }
Property Value
Type |
---|
System.String |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
// Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "Syncfusion";
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations;
doc.Security.UserPassword = "123";
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit
doc.Security.OwnerPassword = "Syncfusion"
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations
doc.Security.UserPassword = "123"
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)
See Also
Permissions
Gets or sets the permissions when the document is opened with user password.
Declaration
public PdfPermissionsFlags Permissions { get; set; }
Property Value
Type |
---|
PdfPermissionsFlags |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
// Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "Syncfusion";
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations | PdfPermissionsFlags.Print;
doc.Security.UserPassword = "123";
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit
doc.Security.OwnerPassword = "Syncfusion"
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations | PdfPermissionsFlags.Print
doc.Security.UserPassword = "123"
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)
See Also
UserPassword
Gets or sets the user password which is required when the PDF document is opened in a viewer.
Declaration
public string UserPassword { get; set; }
Property Value
Type |
---|
System.String |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
// Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit;
doc.Security.OwnerPassword = "Syncfusion";
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations;
doc.Security.UserPassword = "123";
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Set the documents permission settings
doc.Security.KeySize = PdfEncryptionKeySize.Key128Bit
doc.Security.OwnerPassword = "Syncfusion"
doc.Security.Permissions = PdfPermissionsFlags.EditAnnotations
doc.Security.UserPassword = "123"
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)
See Also
Methods
ResetPermissions(PdfPermissionsFlags)
Logically ANDs flag and inverted mask and return result.
Declaration
public PdfPermissionsFlags ResetPermissions(PdfPermissionsFlags flags)
Parameters
Type | Name | Description |
---|---|---|
PdfPermissionsFlags | flags | The mask of set bit that should be cleared in the result. |
Returns
Type | Description |
---|---|
PdfPermissionsFlags | The ANDed value of flag and inverted mask. |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
PdfSecurity security = doc.Security;
security.ResetPermissions(PdfPermissionsFlags.AssembleDocument);
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
'Document security
Dim security As PdfSecurity = doc.Security
security.ResetPermissions(PdfPermissionsFlags.AssembleDocument)
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)
See Also
SetPermissions(PdfPermissionsFlags)
Logically ORs flag and mask and return result.
Declaration
public PdfPermissionsFlags SetPermissions(PdfPermissionsFlags flags)
Parameters
Type | Name | Description |
---|---|---|
PdfPermissionsFlags | flags | The mask of set bit that should be set in the result. |
Returns
Type | Description |
---|---|
PdfPermissionsFlags | The ORed value of flag and mask. |
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
PdfSecurity security = doc.Security;
security.SetPermissions(PdfPermissionsFlags.AssembleDocument);
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10);
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, new PointF(10,10));
doc.Save("Security.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
'Document security
Dim security As PdfSecurity = doc.Security
security.SetPermissions(PdfPermissionsFlags.AssembleDocument)
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = doc.Pages.Add()
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10)
page.Graphics.DrawString("Permission",font,PdfBrushes.Blue, New PointF(10,10))
doc.Save("Security.pdf")
doc.Close(True)