PDF-Verschlüsselung & -Entschlüsselung Dieses Codebeispiel zeigt, wie man mit der leistungsstarken C# .NET-PDF-Bibliothek von IronPDF Metadaten ändert, PDF-Dateien schreibgeschützt macht, Berechtigungen konfiguriert und das Passwort für die Dokumentenverschlüsselung ändert. Um zu beginnen, importieren Sie ein bestehendes PDF-Dokument mit der Methode "Öffnen". Diese Methode kann zum Öffnen passwortgeschützter Dokumente verwendet werden, indem das Passwort als zweiter Parameter angegeben wird, was eine robuste Handhabung gesicherter Dateien ermöglicht. Um neue Metadateninformationen festzulegen, erstellen Sie zunächst ein Wörterbuch und fügen Sie Schlüssel-Wert-Paare für Metadaten hinzu, z. B. den Autor und die Schlüsselwörter. Verwenden Sie die Methode overrideMetadata in IronPDF, um die neuen Metadaten effektiv auf das PDF-Dokument anzuwenden. Als Nächstes entfernen Sie die Passwörter und die Verschlüsselung mit der von IronPDF bereitgestellten Methode removePasswordsAndEncryption und konfigurieren die PDF-Datei als schreibgeschützt, indem Sie mit der Methode makePdfDocumentReadOnly ein neues Passwort festlegen, um die Integrität und Sicherheit des Dokuments zu gewährleisten. Berechtigungen für das PDF-Dokument werden über ein Objekt namens "permissions" konfiguriert, das angibt, ob bestimmte Aktionen wie Anmerkungen, Inhaltsextraktion, Ausfüllen von Formularen und Drucken erlaubt oder verboten sind. Übergeben Sie das Permissions-Objekt an die Methode setPermission, um die Zugänglichkeitsfunktionen des Dokuments genau zu steuern. Ändern Sie schließlich das Kennwort für die Dokumentenverschlüsselung in "my-password" und speichern Sie die geänderte PDF-Datei als "secured.pdf", um die Möglichkeiten von IronPDF für die sichere Dokumentenverwaltung bei der Anwendungsentwicklung zu demonstrieren. // Import the necessary namespace. using IronPdf; class PdfExample { static void Main() { // Open an existing PDF document. If the document is password protected, provide the password. var pdf = IronPdf.PdfDocument.FromFile("existing.pdf", "document-password"); // Initialize a dictionary to store metadata key-value pairs. var newMetadata = new Dictionary<string, string> { { "Author", "New Author" }, { "Keywords", "PDF, Documentation, Example" } }; // Apply the new metadata to the PDF document. pdf.OverrideMetadata(newMetadata); // Remove any existing passwords and encryption. pdf.RemovePasswordsAndEncryption(); // Make the PDF document read-only by setting a read-only password. pdf.MakePdfDocumentReadOnly("read-only-password"); // Define and set the permissions for the PDF document. var permissions = new PdfPermissions { AllowAnnotations = false, AllowContentExtraction = false, AllowFormFilling = true, AllowPrinting = false, AllowDocumentAssembly = false }; pdf.SetPermissions(permissions); // Change the document encryption password. pdf.SaveAs("secured.pdf", "my-password"); // Save the modified PDF with a new security password. } } // Import the necessary namespace. using IronPdf; class PdfExample { static void Main() { // Open an existing PDF document. If the document is password protected, provide the password. var pdf = IronPdf.PdfDocument.FromFile("existing.pdf", "document-password"); // Initialize a dictionary to store metadata key-value pairs. var newMetadata = new Dictionary<string, string> { { "Author", "New Author" }, { "Keywords", "PDF, Documentation, Example" } }; // Apply the new metadata to the PDF document. pdf.OverrideMetadata(newMetadata); // Remove any existing passwords and encryption. pdf.RemovePasswordsAndEncryption(); // Make the PDF document read-only by setting a read-only password. pdf.MakePdfDocumentReadOnly("read-only-password"); // Define and set the permissions for the PDF document. var permissions = new PdfPermissions { AllowAnnotations = false, AllowContentExtraction = false, AllowFormFilling = true, AllowPrinting = false, AllowDocumentAssembly = false }; pdf.SetPermissions(permissions); // Change the document encryption password. pdf.SaveAs("secured.pdf", "my-password"); // Save the modified PDF with a new security password. } } ' Import the necessary namespace. Imports IronPdf Friend Class PdfExample Shared Sub Main() ' Open an existing PDF document. If the document is password protected, provide the password. Dim pdf = IronPdf.PdfDocument.FromFile("existing.pdf", "document-password") ' Initialize a dictionary to store metadata key-value pairs. Dim newMetadata = New Dictionary(Of String, String) From { {"Author", "New Author"}, {"Keywords", "PDF, Documentation, Example"} } ' Apply the new metadata to the PDF document. pdf.OverrideMetadata(newMetadata) ' Remove any existing passwords and encryption. pdf.RemovePasswordsAndEncryption() ' Make the PDF document read-only by setting a read-only password. pdf.MakePdfDocumentReadOnly("read-only-password") ' Define and set the permissions for the PDF document. Dim permissions = New PdfPermissions With { .AllowAnnotations = False, .AllowContentExtraction = False, .AllowFormFilling = True, .AllowPrinting = False, .AllowDocumentAssembly = False } pdf.SetPermissions(permissions) ' Change the document encryption password. pdf.SaveAs("secured.pdf", "my-password") ' Save the modified PDF with a new security password. End Sub End Class $vbLabelText $csharpLabel Explore PDF Encryption & Decryption Code Example Verwandte Doku-Links Auf Github ansehen Verwandtes Tutorial Verwandte Anleitung Klassendokumentation Sprachpakete herunterladen IronPDF DLL herunterladen (Windows, Linux, Azure) Bereit anzufangen? Version: 2025.11 gerade veröffentlicht Kostenlose npm-Installation Lizenzen anzeigen
In einer Live-Umgebung testen Testen Sie ohne Wasserzeichen in der Produktion.Funktioniert dort, wo Sie es brauchen.
Voll funktionsfähiges Produkt Erhalten Sie 30 Tage voll funktionsfähiges Produkt.In wenigen Minuten einsatzbereit.
24/5 technischer Support Voller Zugriff auf unser Support-Engineering-Team während Ihrer Produktprobe