Option Explicit
Private Sub CrypterPDF(ByVal sNomfichier As String, ByVal sOutput As String)
Dim pdf As Object, Crypt As Object
Set Crypt = CreateObject("pdfforge.Pdf.PDFEncryptor")
With Crypt
.AllowAssembly = False
.AllowCopy = False
.AllowFillIn = False
.AllowModifyAnnotations = False
.AllowModifyContents = False
.AllowPrinting = True
.AllowPrintingHighResolution = True
.AllowScreenreaders = False
.EncryptionMethod = 2
.ownerPassword = "master"
.userPassword = ""
End With
Set pdf = CreateObject("pdfforge.Pdf.Pdf")
pdf.EncryptPDFFile sNomfichier, sOutput, Crypt
Set pdf = Nothing
Set Crypt = Nothing
End Sub
Sub Test_01()
Dim Fichier As Variant, FSO As Object, sNom As String
Dim FD As FileDialog
Application.StatusBar = ""
Set FD = Application.FileDialog(msoFileDialogOpen)
With FD
.InitialFileName = ThisDocument.Path & "\"
If .Show = -1 Then
Fichier = FD.SelectedItems(1)
Else
Exit Sub
End If
End With
Set FSO = CreateObject("Scripting.FileSystemObject")
sNom = FSO.GetBaseName(Fichier)
Set FSO = Nothing
CrypterPDF Fichier, ThisDocument.Path & "\" & sNom & "_AES.Pdf"
Application.StatusBar = "Terminé"
End Sub
Sub Test_02()
Dim Fichier As Variant, FSO As Object, sNom As String
Fichier = "C:\...\...\Catalogue.pdf"
Set FSO = CreateObject("Scripting.FileSystemObject")
sNom = FSO.GetBaseName(Fichier)
Set FSO = Nothing
CrypterPDF Fichier, ThisDocument.Path & "\" & sNom & "_AES.Pdf"
End Sub