using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SelectPdf;

namespace SelectPdf.Samples
{
    public partial class advanced_pdf_security : System.Web.UI.Page
    {
        protected void BtnCreatePdf_Click(object sender, EventArgs e)
        {
            // the initial file
            string file = Server.MapPath("~/files/doc1.pdf");

            // the certificate
            string certFile = Server.MapPath("~/files/selectpdf.pfx");

            // load the pdf document using the advanced security manager
            PdfSecurityManager security = new PdfSecurityManager();
            security.Load(file);

            // encryption algorithm and key length
            security.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES;
            security.EncryptionKeySize = PdfEncryptionKeySize.EncryptKey256Bit;

            // set document passwords
            security.OwnerPassword = "test1";
            security.UserPassword = "test2";

            //set document permissions
            security.CanAssembleDocument = false;
            security.CanCopyContent = true;
            security.CanEditAnnotations = true;
            security.CanEditContent = true;
            security.CanFillFields = true;
            security.CanPrint = true;

            // add the digital signature
            security.Sign(certFile, "selectpdf");

            // save pdf document
            security.Save(Response, false, "Sample.pdf");

            // close pdf document
            security.Close();
        }
    }
}