當(dāng)您使用密碼保護(hù) PDF 文檔時(shí),您可以選擇指定一組權(quán)限。權(quán)限決定用戶如何與文件交互。例如,您可以對(duì)文檔應(yīng)用權(quán)限以禁止用戶打印或使用剪切和粘貼操作。本文演示如何在C# 和 VB.NET中使用Spire.PDF for .NET更改 PDF 文檔的安全權(quán)限。
Spire.PDF for .NET?是一款獨(dú)立 PDF 控件,用于 .NET 程序中創(chuàng)建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫(kù),開(kāi)發(fā)人員可以新建一個(gè) PDF 文檔或者對(duì)現(xiàn)有的 PDF 文檔進(jìn)行處理,且無(wú)需安裝 Adobe Acrobat。
E-iceblue?功能類庫(kù)Spire 系列文檔處理組件均由中國(guó)本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國(guó)家的技術(shù)或法律法規(guī)限制,同時(shí)適配國(guó)產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國(guó)產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
Spire.PDF for.net下載? ?Spire.PDF for java下載
安裝適用于 .NET 的 Spire.PDF
首先,您需要將 Spire.PDF for .NET 包中包含的 DLL 文件添加為 .NET 項(xiàng)目中的引用。DLL 文件可以從此鏈接下載或通過(guò)NuGet安裝。
PM> Install-Package Spire.PDF
更改 PDF 文檔的安全權(quán)限
以下是使用 Spire.PDF for .NET 將安全權(quán)限應(yīng)用于 PDF 文檔的步驟。
- 創(chuàng)建一個(gè)PdfDocument對(duì)象。
- 使用PdfDocument.LoadFileFile()方法加載示例 PDF 文件。
- 指定打開(kāi)密碼和權(quán)限密碼。打開(kāi)密碼可以設(shè)置為空,這樣生成的文檔就不需要密碼打開(kāi)。
- 使用打開(kāi)密碼和權(quán)限密碼對(duì)文檔進(jìn)行加密,并使用PdfDocument.Security.Encypt()方法設(shè)置安全權(quán)限。該方法以PdfPermissionsFlags枚舉作為參數(shù),定義用戶對(duì)加密文檔的訪問(wèn)權(quán)限。
- 使用PdfDocument.SaveToFile()方法將文檔保存到另一個(gè) PDF 文件。
【C#】
using Spire.Pdf; using Spire.Pdf.Security; namespace ChangeSecurityPermission { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample PDF file doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf"); //Specify open password string openPsd = string.Empty; //Specify permission password string permissionPsd = "e-iceblue"; //Encrypt the document with open password and permission password, and set the permissions and encryption key size doc.Security.Encrypt(openPsd, permissionPsd, PdfPermissionsFlags.FullQualityPrint, PdfEncryptionKeySize.Key128Bit); //Save the document to another PDF file doc.SaveToFile("SecurityPermissions.pdf"); } } }
【VB.NET】
using Spire.Pdf; using Spire.Pdf.Security; namespace ChangeSecurityPermission { class Program { static void Main(string[] args) { //Create a PdfDocument object PdfDocument doc = new PdfDocument(); //Load a sample PDF file doc.LoadFromFile(@"C:\Users\Administrator\Desktop\sample.pdf"); //Specify open password string openPsd = string.Empty; //Specify permission password string permissionPsd = "e-iceblue"; //Encrypt the document with open password and permission password, and set the permissions and encryption key size doc.Security.Encrypt(openPsd, permissionPsd, PdfPermissionsFlags.FullQualityPrint, PdfEncryptionKeySize.Key128Bit); //Save the document to another PDF file doc.SaveToFile("SecurityPermissions.pdf"); } } }
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-804364.html
以上便是如何使更改 PDF 文檔的安全權(quán)限,如果您有其他問(wèn)題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程~文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-804364.html
到了這里,關(guān)于PDF控件Spire.PDF for .NET【安全】演示:更改 PDF 文檔的安全權(quán)限的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!