PDF加密与解密
可以应用粒度元数据和安全设置。 这现在包括将PDF文档限制为不可打印、只读和加密的功能。 支持对PDF文档进行128位加密、解密和密码保护。
如何在 C&num 中为 PDF 添加密码加密;
- 安装 C# 库,为 PDF 文件添加密码加密功能
- 打开要加密的现有 PDF 文档
- 设置
密码
属性 - 将加密的 PDF 文档保存到指定位置
- 用两行 C# 代码执行步骤 2 和 3。
using IronPdf; using System; //Open an Encrypted File, alternatively create a new PDF from Html var pdf = PdfDocument.FromFile("encrypted.pdf", "password"); //Edit file metadata pdf.MetaData.Author = "Satoshi Nakamoto"; pdf.MetaData.Keywords = "SEO, Friendly"; pdf.MetaData.ModifiedDate = DateTime.Now; //Edit file security settings //The following code makes a PDF read only and will disallow copy & paste and printing pdf.SecuritySettings.RemovePasswordsAndEncryption(); pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key"); pdf.SecuritySettings.AllowUserAnnotations = false; pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserFormData = false; pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights; // change or set the document encrpytion password pdf.Password = "my-password"; pdf.SaveAs("secured.pdf");
Imports IronPdf Imports System 'Open an Encrypted File, alternatively create a new PDF from Html Private pdf = PdfDocument.FromFile("encrypted.pdf", "password") 'Edit file metadata pdf.MetaData.Author = "Satoshi Nakamoto" pdf.MetaData.Keywords = "SEO, Friendly" pdf.MetaData.ModifiedDate = DateTime.Now 'Edit file security settings 'The following code makes a PDF read only and will disallow copy & paste and printing pdf.SecuritySettings.RemovePasswordsAndEncryption() pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key") pdf.SecuritySettings.AllowUserAnnotations = False pdf.SecuritySettings.AllowUserCopyPasteContent = False pdf.SecuritySettings.AllowUserFormData = False pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights ' change or set the document encrpytion password pdf.Password = "my-password" pdf.SaveAs("secured.pdf")
Install-Package IronPdf
可以应用粒度元数据和安全设置。 这现在包括将PDF文档限制为不可打印、只读和加密的功能。 支持对PDF文档进行128位加密、解密和密码保护。
密码
属性