GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetEncryptionMode Method
Example





In This Topic
GetEncryptionMode Method (GdPicturePDF)
In This Topic
Returns the security handler which has been used to encrypt the currently loaded PDF document.

The file's security handler provides a mechanism that not only implements encryption in PDF documents, but also stores all data related to this process. The PDF specification defines two security handlers: Standard Security Handler and Public-Key Security Handler. Other applications may provide security handlers of their own.

Syntax
'Declaration
 
Public Function GetEncryptionMode() As PdfEncryptionMode
public PdfEncryptionMode GetEncryptionMode()
public function GetEncryptionMode(): PdfEncryptionMode; 
public function GetEncryptionMode() : PdfEncryptionMode;
public: PdfEncryptionMode GetEncryptionMode(); 
public:
PdfEncryptionMode GetEncryptionMode(); 

Return Value

A member of the PdfEncryptionMode enumeration. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
You should apply this method on an encrypted PDF document only (see the example below).

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Example
How to find out the used security handler for the encrypted PDF document.
Dim caption As String = "Example: GetEncryptionMode"
Dim gdpicturePDF As New GdPicturePDF()
'Please see the example in the SetPassword method for creating this file.
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("encrypted.pdf", False)
If status = GdPictureStatus.OK Then
    Dim emode As PdfEncryptionMode = PdfEncryptionMode.UnKnown
    If gdpicturePDF.IsEncrypted() Then
        emode = gdpicturePDF.GetEncryptionMode()
        status = gdpicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            MessageBox.Show("This PDF document is encrypted, the security handler is: " + emode.ToString(), caption)
        Else
            MessageBox.Show("The GetEncryptionMode() method has failed with the status: " + status.ToString(), caption)
        End If
            
        'You need to provide the correct password here.
        If gdpicturePDF.SetPassword("user") = GdPictureStatus.OK Then
            emode = gdpicturePDF.GetEncryptionMode()
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                MessageBox.Show("This PDF document has been decrypted, the security handler is: " + emode.ToString(), caption)
            End If
        End If
    Else
        emode = gdpicturePDF.GetEncryptionMode()
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            MessageBox.Show("The PDF document is not encrypted. The security handler is: " + emode.ToString(), caption)
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetEncryptionMode";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Please see the example in the SetPassword method for creating this file.
GdPictureStatus status = gdpicturePDF.LoadFromFile("encrypted.pdf", false);
if (status == GdPictureStatus.OK)
{
    PdfEncryptionMode emode = PdfEncryptionMode.UnKnown;
    if (gdpicturePDF.IsEncrypted())
    {
        emode = gdpicturePDF.GetEncryptionMode();
        status = gdpicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            MessageBox.Show("This PDF document is encrypted, the security handler is: " + emode.ToString(), caption);
        }
        else
        {
            MessageBox.Show("The GetEncryptionMode() method has failed with the status: " + status.ToString(), caption);
        }
            
        //You need to provide the correct password here.
        if (gdpicturePDF.SetPassword("user") == GdPictureStatus.OK)
        {
            emode = gdpicturePDF.GetEncryptionMode();
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                MessageBox.Show("This PDF document has been decrypted, the security handler is: " + emode.ToString(), caption);
            }
        }
    }
    else
    {
        emode = gdpicturePDF.GetEncryptionMode();
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            MessageBox.Show("The PDF document is not encrypted. The security handler is: " + emode.ToString(), caption);
        }
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also