Table of Contents

Class PdfSecurity

Namespace
Syncfusion.Pdf.Security
Assembly
Syncfusion.Pdf.Portable.dll

Represents the security settings of the PDF document.

public class PdfSecurity
Inheritance
PdfSecurity
Inherited Members

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.

public PdfSecurity()

Properties

Algorithm

Gets or sets the type of encryption algorithm used.

public PdfEncryptionAlgorithm Algorithm { get; set; }

Property Value

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.

public PdfEncryptionOptions EncryptionOptions { get; set; }

Property Value

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.

public PdfEncryptionKeySize KeySize { get; set; }

Property Value

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.

public string OwnerPassword { get; set; }

Property Value

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.

public PdfPermissionsFlags Permissions { get; set; }

Property Value

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.

public string UserPassword { get; set; }

Property Value

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.

public PdfPermissionsFlags ResetPermissions(PdfPermissionsFlags flags)

Parameters

flags PdfPermissionsFlags

The mask of set bit that should be cleared in the result.

Returns

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.

public PdfPermissionsFlags SetPermissions(PdfPermissionsFlags flags)

Parameters

flags PdfPermissionsFlags

The mask of set bit that should be set in the result.

Returns

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)
See Also