Browse Source

Add Decrypt method and update encryption settings in DocumentOperation and JobConfiguration

Marcin Ziąbek 7 months ago
parent
commit
ac82824d61

+ 11 - 2
Source/QuestPDF/Fluent/DocumentOperation.cs

@@ -375,6 +375,15 @@ public sealed class DocumentOperation
             };
             };
         }
         }
     }
     }
+
+    /// <summary>
+    /// Removes any existing encryption from the current PDF document, effectively making it accessible without a password or encryption restrictions.
+    /// </summary>
+    public DocumentOperation Decrypt()
+    {
+        Configuration.Decrypt = string.Empty;
+        return this;
+    }
     
     
     /// <summary>
     /// <summary>
     /// Encrypts the document using 40-bit encryption, applying specified owner and user passwords along with defined permissions.
     /// Encrypts the document using 40-bit encryption, applying specified owner and user passwords along with defined permissions.
@@ -392,8 +401,8 @@ public sealed class DocumentOperation
             {
             {
                 Annotate = FormatBooleanFlag(encryption.AllowAnnotation),
                 Annotate = FormatBooleanFlag(encryption.AllowAnnotation),
                 Extract = FormatBooleanFlag(encryption.AllowContentExtraction),
                 Extract = FormatBooleanFlag(encryption.AllowContentExtraction),
-                Modify = FormatBooleanFlag(encryption.AllowModification),
-                Print = FormatBooleanFlag(encryption.AllowPrinting)
+                Modify = encryption.AllowModification ? "all" : "none",
+                Print = encryption.AllowPrinting ? "full" : "none",
             }
             }
         };
         };
         
         

+ 4 - 1
Source/QuestPDF/Qpdf/JobConfiguration.cs

@@ -19,6 +19,8 @@ sealed class JobConfiguration
     [Name("addAttachment")] public ICollection<AddDocumentAttachment>? AddAttachment { get; set; }
     [Name("addAttachment")] public ICollection<AddDocumentAttachment>? AddAttachment { get; set; }
     
     
     [Name("encrypt")] public EncryptionSettings? Encrypt { get; set; } 
     [Name("encrypt")] public EncryptionSettings? Encrypt { get; set; } 
+    [Name("allowWeakCrypto")] public string AllowWeakCrypto { get; set; } = string.Empty;
+    [Name("decrypt")] public string? Decrypt { get; set; } 
     [Name("linearize")] public string? Linearize { get; set; }
     [Name("linearize")] public string? Linearize { get; set; }
     [Name("newlineBeforeEndstream")] public string? NewlineBeforeEndstream { get; set; } = string.Empty;
     [Name("newlineBeforeEndstream")] public string? NewlineBeforeEndstream { get; set; } = string.Empty;
     
     
@@ -62,7 +64,7 @@ sealed class JobConfiguration
     public sealed class Encryption40Bit
     public sealed class Encryption40Bit
     {
     {
         [Name("annotate")] public string Annotate { get; set; }
         [Name("annotate")] public string Annotate { get; set; }
-        [Name("extract")] public string Extract { get; set; }
+        [Name("extract")] public string Extract { get; set; } 
         [Name("modify")] public string Modify { get; set; }
         [Name("modify")] public string Modify { get; set; }
         [Name("print")] public string Print { get; set; }
         [Name("print")] public string Print { get; set; }
     }
     }
@@ -74,6 +76,7 @@ sealed class JobConfiguration
         [Name("extract")] public string Extract { get; set; }
         [Name("extract")] public string Extract { get; set; }
         [Name("form")] public string Form { get; set; }
         [Name("form")] public string Form { get; set; }
         [Name("print")] public string? Print { get; set; }
         [Name("print")] public string? Print { get; set; }
+        [Name("useAes")] public string? UseAES { get; set; } = "y";
         [Name("cleartextMetadata")] public string? CleartextMetadata { get; set; }
         [Name("cleartextMetadata")] public string? CleartextMetadata { get; set; }
     }
     }