And reference PdfSharp. dll
Using sharp. Pdf;
Using System. IO;
public string PDFSecurity(string strSourcePDFFile, string strDestPDFFile, bool AddUserPassword, string strPassword) { try { PdfSharp.Pdf.PdfDocument pdfsourcedoc = PdfSharp.Pdf.IO.PdfReader.Open(strSourcePDFFile, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify); pdfsourcedoc.SecuritySettings.DocumentSecurityLevel = PdfSharp.Pdf.Security.PdfDocumentSecurityLevel.Encrypted128Bit; pdfsourcedoc.SecuritySettings.OwnerPassword = "adamtest"; pdfsourcedoc.SecuritySettings.PermitAccessibilityExtractContent = false; pdfsourcedoc.SecuritySettings.PermitAnnotations = false; pdfsourcedoc.SecuritySettings.PermitAssembleDocument = false; pdfsourcedoc.SecuritySettings.PermitExtractContent = false; pdfsourcedoc.SecuritySettings.PermitFormsFill = false; pdfsourcedoc.SecuritySettings.PermitFullQualityPrint = false; pdfsourcedoc.SecuritySettings.PermitModifyDocument = false; pdfsourcedoc.SecuritySettings.PermitPrint = false; if (AddUserPassword == true) { pdfsourcedoc.SecuritySettings.UserPassword = strPassword; } pdfsourcedoc.Save(strDestPDFFile); return ""; } catch (Exception ex) { return ex.ToString(); } }