GdPicture.NET.14 (COM - ActiveX)~GdPicture14_namespace / GdPicture.NET.14 (COM - ActiveX)~GdPicture14.GdPicturePDF / 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. Please always use the GdPicturePDF.GetStat method 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 oGdPicturePDF As New GdPicturePDF()
    'Please see the example in the SetPassword method for creating this file.
    Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("encrypted.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim emode As PdfEncryptionMode = PdfEncryptionMode.UnKnown
        If oGdPicturePDF.IsEncrypted() Then
            emode = oGdPicturePDF.GetEncryptionMode()
            status = oGdPicturePDF.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 oGdPicturePDF.SetPassword("user") = GdPictureStatus.OK Then
                emode = oGdPicturePDF.GetEncryptionMode()
                If oGdPicturePDF.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 = oGdPicturePDF.GetEncryptionMode()
            If oGdPicturePDF.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
    oGdPicturePDF.Dispose()
    string caption = "Example: GetEncryptionMode";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    //Please see the example in the SetPassword method for creating this file.
    GdPictureStatus status = oGdPicturePDF.LoadFromFile("encrypted.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        PdfEncryptionMode emode = PdfEncryptionMode.UnKnown;
        if (oGdPicturePDF.IsEncrypted())
        {
            emode = oGdPicturePDF.GetEncryptionMode();
            status = oGdPicturePDF.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 (oGdPicturePDF.SetPassword("user") == GdPictureStatus.OK)
            {
                emode = oGdPicturePDF.GetEncryptionMode();
                if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    MessageBox.Show("This PDF document has been decrypted, the security handler is: " + emode.ToString(), caption);
                }
            }
        }
        else
        {
            emode = oGdPicturePDF.GetEncryptionMode();
            if (oGdPicturePDF.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);
    }
    oGdPicturePDF.Dispose();
    See Also