PdfSharp.dll 更改pdf 設置 如不能複製,列印等

下載并引用PdfSharp.dll

 

using PdfSharp.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();

            }
        
        }

 

posted @ 2011-01-28 08:55  Nina  阅读(1472)  评论(0编辑  收藏  举报