» C# Sample Code: Encrypt PDF with C# (C-Sharp)

                using System;
                using System.Collections.Generic;
                using System.ComponentModel;
                using System.Data;
                using System.Drawing;
                using System.Linq;
                using System.Text;
                using System.Windows.Forms;
                using PDFEncryptX;
                
                namespace Application1
                {
                    public partial class Form1 : Form
                    {
                        public Form1()
                        {
                            InitializeComponent();
                        }
                
                
                        private void button1_Click(object sender, EventArgs e)
                        {
                
                            EncryptLibClass obj = new PDFEncryptX.EncryptLibClass();
                
                            obj.SetLicenseKey("License Code");
                
                            int iRtn = obj.LoadFromFile(".\\PDFEncryptX.pdf", "");
                
                            if (iRtn == 1)
                            {
                                if (obj.IsEncrypted == 1)
                                {
                                    textBox1.Text = "YES";
                                }
                                else
                                {
                                    textBox1.Text = "NO";
                                }
                                textBox2.Text = obj.PageCount.ToString();
                                textBox3.Text = obj.FileSize.ToString();
                            }
                
                            //Create Permissions: Can not to print, copy and edit.
                            int iPermissions = obj.CreatePermissions(0, 0, 0, 1, 1, 1, 1, 1);
                
                            //Call encrypt method
                            int iValue = obj.Encrypt(".\\PDFEncryptX_CanNot_Print_Copy_Edit.pdf", 2, iPermissions, "", "");
                            switch(iValue)
                            {
                                case 0: textBox4.Text = "0->Encrypt failed"; break;
                                case 1: textBox4.Text = "1->Encrypt successful"; break;
                                case 2: textBox4.Text = "2->Ignore - file already encrypted"; break;
                            }
                        }
                
                        private void button2_Click(object sender, EventArgs e)
                        {
                            Close();
                        }
                    }
                }