Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / GetRight Method
A member of the PdfRight enumeration. You need to specify the permisson you want to find out if it is allowed or not.
Example





In This Topic
    GetRight Method (GdPicturePDF)
    In This Topic
    Returns if the provided access permission is granted within the currently loaded PDF document.
    Syntax
    'Declaration
     
    
    Public Function GetRight( _
       ByVal Right As PdfRight _
    ) As Boolean
    public bool GetRight( 
       PdfRight Right
    )
    public function GetRight( 
        Right: PdfRight
    ): Boolean; 
    public function GetRight( 
       Right : PdfRight
    ) : boolean;
    public: bool GetRight( 
       PdfRight Right
    ) 
    public:
    bool GetRight( 
       PdfRight Right
    ) 

    Parameters

    Right
    A member of the PdfRight enumeration. You need to specify the permisson you want to find out if it is allowed or not.

    Return Value

    true if the access permission you have specified is allowed, otherwise false. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

    You should apply this method on a decrypted PDF document only. If your document is still encrypted, the GetRight method returns false and the GetStat method returns GdPictureStatus.PdfDocumentMustBeUnencrypted.

    You need to decrypt the PDF document at first using the SetPassword method with specifyting either the correct user password or the owner password.

    Example
    How to correctly find out the access permissions of the PDF document.
    Dim caption As String = "Example: GetRight"
    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 encrypted As Boolean = oGdPicturePDF.IsEncrypted()
        If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
            If encrypted Then
                'Setting the user password.
                status = oGdPicturePDF.SetPassword("user")
                'Try the same with providing the owner password.
                'status = oGdPicturePDF.SetPassword("owner");
                If status = GdPictureStatus.OK Then
                    encrypted = oGdPicturePDF.IsEncrypted()
                    If (oGdPicturePDF.GetStat() = GdPictureStatus.OK) AndAlso Not encrypted Then
                        Dim encryptScheme As PdfEncryption = oGdPicturePDF.GetEncryptionScheme()
                        status = oGdPicturePDF.GetStat()
                        If status = GdPictureStatus.OK Then
                            Dim permList As String = ""
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanView) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanView.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanPrint) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanPrint.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanModify) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanModify.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanCopy) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanCopy.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanAddNotes) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanAddNotes.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanFillFields) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanFillFields.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanCopyAccess) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanCopyAccess.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanAssemble) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanAssemble.ToString() + vbCrLf
                            End If
                            If oGdPicturePDF.GetRight(PdfRight.PdfRightCanPrintFull) AndAlso (oGdPicturePDF.GetStat() = GdPictureStatus.OK) Then
                                permList = permList + PdfRight.PdfRightCanPrintFull.ToString() + vbCrLf
                            End If
                            MessageBox.Show("PDF encryption is " + encryptScheme.ToString() + "." + vbCrLf + "Access permissions are: " + vbCrLf + permList.ToString(), caption)
                        Else
                            MessageBox.Show("The GetEncryptionScheme() method has failed with the status: " + status.ToString())
                        End If
                    End If
                Else
                    MessageBox.Show("You have probably provided a bad password.", caption)
                End If
            Else
                MessageBox.Show("The file is unencrypted.", caption)
            End If
        End If
    Else
        MessageBox.Show("The file can't be loaded.", caption)
    End If
    oGdPicturePDF.Dispose()
    string caption = "Example: GetRight";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    GdPictureStatus status = oGdPicturePDF.LoadFromFile("encrypted.pdf", false);
    //Please see the example in the SetPassword method for creating this file.
    if (status == GdPictureStatus.OK)
    {
        bool encrypted = oGdPicturePDF.IsEncrypted();
        if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
        {
            if (encrypted)
            {
                //Setting the user password.
                status = oGdPicturePDF.SetPassword("user");
                //Try the same with providing the owner password.
                //status = oGdPicturePDF.SetPassword("owner");
                if (status == GdPictureStatus.OK)
                {
                    encrypted = oGdPicturePDF.IsEncrypted();
                    if ((oGdPicturePDF.GetStat() == GdPictureStatus.OK) && !encrypted)
                    {
                        PdfEncryption encryptScheme = oGdPicturePDF.GetEncryptionScheme();
                        status = oGdPicturePDF.GetStat();
                        if (status == GdPictureStatus.OK)
                        {
                            string permList = "";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanView) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanView.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanPrint) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanPrint.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanModify) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanModify.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanCopy) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanCopy.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanAddNotes) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanAddNotes.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanFillFields) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanFillFields.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanCopyAccess) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanCopyAccess.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanAssemble) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanAssemble.ToString() + "\n";
                            if (oGdPicturePDF.GetRight(PdfRight.PdfRightCanPrintFull) && (oGdPicturePDF.GetStat() == GdPictureStatus.OK))
                                permList = permList + PdfRight.PdfRightCanPrintFull.ToString() + "\n";
                            MessageBox.Show("PDF encryption is " + encryptScheme.ToString() + ".\nAccess permissions are: \n" + permList.ToString(), caption);
                        }
                        else
                        {
                            MessageBox.Show("The GetEncryptionScheme() method has failed with the status: " + status.ToString());
                        }
                    }
                }
                else
                {
                    MessageBox.Show("You have probably provided a bad password.", caption);
                }
            }
            else
            {
                MessageBox.Show("The file is unencrypted.", caption);
            }
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", caption);
    }
    oGdPicturePDF.Dispose();
    See Also