Products
PDFKit.NET 4.0
Created
7/17/2015
Tags
Security

This code sample shows how you can view the security settings of a PDF document.

//read document with security settings
using (FileStream inFile = new FileStream("PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read))
{
    // open the source document
    Document document = new Document( inFile );

    // display settings, note that the passwords will not be available.
    PasswordSecurity passwordSecurity = document.Security as PasswordSecurity;
         
    Console.WriteLine("Assembly: {0}", passwordSecurity.Assembly);
    Console.WriteLine("AuthorCommentsFormFields: {0}", passwordSecurity.AuthorCommentsFormFields);
    Console.WriteLine("Change: {0}", passwordSecurity.Change);
    Console.WriteLine("CopyExtract: {0}", passwordSecurity.CopyExtract);
    Console.WriteLine("ExtractAccessibilityContents: {0}", passwordSecurity.ExtractAccessibilityContents);
    Console.WriteLine("FormFillSign: {0}", passwordSecurity.FormFillSign);
    Console.WriteLine("Print: {0}", passwordSecurity.Print);
    Console.WriteLine("PrintHighQuality: {0}", passwordSecurity.PrintHighQuality);
    Console.WriteLine("EncryptionLevel: {0}", passwordSecurity.EncryptionLevel);
}
'read document with security settings
Using inFile As New FileStream("PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)
    ' open the source document
    Dim document As New Document(inFile)

    ' display settings, note that the passwords will not be available.
    Dim passwordSecurity As PasswordSecurity = TryCast(document.Security, PasswordSecurity)

    Console.WriteLine("Assembly: {0}", passwordSecurity.Assembly)
    Console.WriteLine("AuthorCommentsFormFields: {0}", passwordSecurity.AuthorCommentsFormFields)
    Console.WriteLine("Change: {0}", passwordSecurity.Change)
    Console.WriteLine("CopyExtract: {0}", passwordSecurity.CopyExtract)
    Console.WriteLine("ExtractAccessibilityContents: {0}", passwordSecurity.ExtractAccessibilityContents)
    Console.WriteLine("FormFillSign: {0}", passwordSecurity.FormFillSign)
    Console.WriteLine("Print: {0}", passwordSecurity.Print)
    Console.WriteLine("PrintHighQuality: {0}", passwordSecurity.PrintHighQuality)
    Console.WriteLine("EncryptionLevel: {0}", passwordSecurity.EncryptionLevel)
End Using