GdPicture.NET.14.API
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. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
It is recommend to use the GdPicturePDF.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 GdPicturePDF.GetRight method returns false and the GdPicturePDF.GetStat method returns GdPictureStatus.PdfDocumentMustBeUnencrypted.

You need to decrypt the PDF document at first using the GdPicturePDF.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 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 encrypted As Boolean = gdpicturePDF.IsEncrypted()
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        If encrypted Then
            'Setting the user password.
            status = gdpicturePDF.SetPassword("user")
            'Try the same with providing the owner password.
            'status = gdpicturePDF.SetPassword("owner");
            If status = GdPictureStatus.OK Then
                encrypted = gdpicturePDF.IsEncrypted()
                If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso Not encrypted Then
                    Dim encryptScheme As PdfEncryption = gdpicturePDF.GetEncryptionScheme()
                    status = gdpicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        Dim permList As String = ""
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanView) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanView.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanPrint) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanPrint.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanModify) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanModify.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanCopy) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanCopy.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanAddNotes) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanAddNotes.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanFillFields) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanFillFields.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanCopyAccess) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanCopyAccess.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanAssemble) AndAlso (gdpicturePDF.GetStat() = GdPictureStatus.OK) Then
                            permList = permList + PdfRight.PdfRightCanAssemble.ToString() + vbCrLf
                        End If
                        If gdpicturePDF.GetRight(PdfRight.PdfRightCanPrintFull) AndAlso (gdpicturePDF.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
gdpicturePDF.Dispose()
string caption = "Example: GetRight";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("encrypted.pdf", false);
//Please see the example in the SetPassword method for creating this file.
if (status == GdPictureStatus.OK)
{
    bool encrypted = gdpicturePDF.IsEncrypted();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        if (encrypted)
        {
            //Setting the user password.
            status = gdpicturePDF.SetPassword("user");
            //Try the same with providing the owner password.
            //status = gdpicturePDF.SetPassword("owner");
            if (status == GdPictureStatus.OK)
            {
                encrypted = gdpicturePDF.IsEncrypted();
                if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) && !encrypted)
                {
                    PdfEncryption encryptScheme = gdpicturePDF.GetEncryptionScheme();
                    status = gdpicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                    {
                        string permList = "";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanView) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanView.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanPrint) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanPrint.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanModify) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanModify.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanCopy) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanCopy.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanAddNotes) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanAddNotes.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanFillFields) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanFillFields.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanCopyAccess) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanCopyAccess.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanAssemble) && (gdpicturePDF.GetStat() == GdPictureStatus.OK))
                            permList = permList + PdfRight.PdfRightCanAssemble.ToString() + "\n";
                        if (gdpicturePDF.GetRight(PdfRight.PdfRightCanPrintFull) && (gdpicturePDF.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);
}
gdpicturePDF.Dispose();
See Also