Option Explicit
Sub SelFichierACrypter_AES_128()
Dim Fichier As Variant, FSO As Object
Dim sNom As String, sExt As String, sDossier As String
ChDir ThisWorkbook.Path & "\"
Fichier = Application.GetOpenFilename("Fichiers PDF (*.Pdf), *.Pdf", Title:="Sélection PDF")
If Fichier = False Then Exit Sub
DoEvents
Set FSO = CreateObject("Scripting.FileSystemObject")
sExt = "_AES.pdf"
sNom = FSO.GetBaseName(Fichier) & sExt
sDossier = FSO.GetParentFolderName(Fichier)
Set FSO = Nothing
CrypterPDF Fichier, sNom
Application.StatusBar = "Cryptage Terminé"
End Sub
Private Sub CrypterPDF(ByVal sNomfichier As String, sOutput As String)
Dim pdf As Object, Crypt As Object
' Nécessite PDFCreator 1.7.3
Set Crypt = CreateObject("pdfforge.Pdf.PDFEncryptor")
With Crypt
.AllowAssembly = False
.AllowCopy = False
.AllowFillIn = False
.AllowModifyAnnotations = False
.AllowModifyContents = False
.AllowPrinting = True
.AllowPrintingHighResolution = True
.AllowScreenreaders = False
' AES 128
.EncryptionMethod = 2
.ownerPassword = "master"
.userPassword = "user"
End With
Set pdf = CreateObject("pdfforge.Pdf.Pdf")
pdf.EncryptPDFFile sNomfichier, sOutput, Crypt
Set pdf = Nothing
Set Crypt = Nothing
End Sub