» Visual Basic Sample Code: Encrypt PDF with Visual Basic

                Private Sub Command1_Click()
                    Dim obj As Object
                    Dim iRtn As Long
                    Dim iPermissions As Long
                  
                    Set obj = CreateObject("PDFEncryptX.EncryptLib")    'Create object
                      
                    obj.SetLicenseKey ("License Code")                  'Set your license key
                  
                    iRtn = obj.LoadFromFile(".\PDFEncryptX.pdf", "")    'Load PDF file
                    'iRtn =  1: loaded successful
                    'iRtn =  0: Load Failed;
                    'iRtn = -1: File not exist
                     
                    'if load file successful, then get relational property.
                    If iRtn = 1 Then
                        If obj.IsEncrypted = 1 Then     'Encrypted PDF ?
                            Text1.Text = "YES"
                        Else
                            Text1.Text = "NO"
                        End If
                        
                        Text2.Text = obj.PageCount      'Page count of PDF
                        
                        Text3.Text = obj.FileSize       'File size of PDF
                    End If
                    
                    'Create Permissions: Can not to print, copy and edit.
                    iPermissions = obj.CreatePermissions(0, 0, 0, 1, 1, 1, 1, 1)
                    
                    'Call encrypt method
                    iRtn = obj.Encrypt(".\PDFEncryptX_CanNot_Print_Copy_Edit.pdf", 2, iPermissions, "", "")
                    If iRtn = 0 Then
                        Text4.Text = "0->Encrypt failed"
                    ElseIf iRtn = 1 Then
                        Text4.Text = "1->Encrypt successful"
                    ElseIf iRtn = 2 Then
                        Text4.Text = "2->Ignore - file already encrypted"
                    End If
                    
                    Set obj = Nothing
                End Sub