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(); } }