修改加密 PDF 的密碼
Spire.PDF for .NET 是一款專門對 Word 文檔進行操作的 .NET 類庫。致力于在于幫助開發人員輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔,而無需安裝 Microsoft Word。
行號用于在每行文本旁邊顯示 Word 自動計算的行數。當我們需要參考合同或法律文件等文檔中的特定行時,它非常有用。word中的行號功能允許我們設置起始值、編號間隔、與文本的距離以及行號的編號方式。使用 Spire.Doc,我們可以實現上述所有功能。本文將介紹如何將 HTML 轉換為 PDF。
歡迎加入spire技術交流群:767755948
修改 PDF 文件的密碼確實是一個理性的選擇,尤其是當密碼已被他人知曉,您的 PDF 文件不再安全時。Spire.PDF for .NET能讓您在C#、VB.NET中修改加密PDF文件的密碼。您可以修改所有者密碼和用戶密碼,并在訪問 PDF 文件時設置用戶限制。現在請看下圖所示的修改加密 PDF 密碼的過程:

從上圖中,你不難發現,第一步是通過所有者密碼解密 PDF 文件。原始的所有者密碼是重要的。你可以用這種方法解密:Spire.Pdf.PdfDocument(string filename, string password)
然后,通過重置所有者密碼和用戶密碼來修改密碼。命名空間 Spire.PDFDocument.Security 中的 PDFSecurity 類不僅可以幫助您設置所有者密碼和用戶密碼,還可以設置用戶權限以限制用戶訪問。
下面顯示了修改加密 PDF 文件密碼的全部代碼,請下載 Spire.PDF for .NET 并安裝到系統上后再查看代碼:
[C#]
01 using Spire.Pdf; 02 using Spire.Pdf.Security; 03 04 namespace modify_PDF_passwords 05 { 06 class Program 07 { 08 static void Main(string[] args) 09 { 10 11 //load a encrypted file and decrypt it 12 String encryptedPdf = @"..\Encrypt.pdf"; 13 PdfDocument doc = new PdfDocument(encryptedPdf, "e-iceblue"); 14 15 //reset PDF passwords and set user password permission 16 doc.Security.OwnerPassword = "Spire.PDF"; 17 doc.Security.UserPassword = "pdfcomponent"; 18 doc.Security.Permissions = PdfPermissionsFlags.Print | PdfPermissionsFlags.FillFields; 19 20 //Save pdf file. 21 doc.SaveToFile("Encryption.pdf"); 22 doc.Close(); 23 //Launching the Pdf file. 24 System.Diagnostics.Process.Start("Encryption.pdf"); 25 26 } 27 } 28 }
[VB.NET]
01 Imports Spire.Pdf 02 Imports Spire.Pdf.Security 03 04 Namespace modify_PDF_passwords 05 Class Program 06 Private Shared Sub Main(args As String()) 07 08 'load a encrypted file and decrypt it 09 Dim encryptedPdf As [String] = "..\Encrypt.pdf" 10 Dim doc As New PdfDocument(encryptedPdf, "e-iceblue") 11 12 'reset PDF passwords and set user password permission 13 doc.Security.OwnerPassword = "Spire.PDF" 14 doc.Security.UserPassword = "pdfcomponent" 15 doc.Security.Permissions = PdfPermissionsFlags.Print Or PdfPermissionsFlags.FillFields 16 17 'Save pdf file. 18 doc.SaveToFile("Encryption.pdf") 19 doc.Close() 20 'Launching the Pdf file. 21 System.Diagnostics.Process.Start("Encryption.pdf") 22 23 End Sub 24 End Class 25 End NamespaceSpire.PDF for .NET是一款.NET PDF組件,可讓您在C#、VB.NET中生成、讀取、編輯和處理PDF文件。