我在Microsoft Access 2007中有一个应用程序,它通过OutputTo ... acFormatPDF生成PDF文件。它工作正常,但现在,有人操纵了生成的PDF,现在我将为我的程序代码添加PDF的保护。我怎么能这样做因为OutputTo似乎没有选择呢?我需要的唯一保护是更改文档。所有其他保护措施(复制,打印,......)都无关联。
答案 0 :(得分:1)
我找到了一种使用AcroJS对PDF进行保护的方法,以及here找到的可实例化COM类列表。我使用“CreateObject”来执行Acrobat对象的后期绑定,但是如果安装了Acrobat,则可以通过进入VBA IDE并单击Tools --->来在项目中添加引用。引用...并选中“Adobe Acrobat x.x类型库”旁边的框(其中x.x是您的Acrobat版本)。如果您没有看到可用,请在Program Files中查找“acrobat.tlb”并通过浏览添加它...
Public Sub ProtectPDF(strFilePath As String, strPolicyName As String)
On Error GoTo ErrHandler
Dim oPDDoc As Object
Dim oJso As Object
Dim oSec As Object
Dim arrPolicies As Variant
Dim PolicyIndex As Integer
Dim i As Integer
Dim success As Boolean
Const PDSaveFull = 1
Set oPDDoc = CreateObject("AcroExch.PDDoc")
If oPDDoc.Open(strFilePath) Then
Set jso = oPDDoc.GetJSObject
Set sec = jso.security
apols = sec.getSecurityPolicies()
PolicyIndex = -1
For i = 0 To UBound(arrPolicies)
If arrPolicies(i).Name = strPolicyName Then
PolicyIndex = i
End If
Next
If Not PolicyIndex = -1 Then
jso.encryptUsingPolicy (arrPolicies(PolicyIndex))
Else
Err.Raise vbObjectError + 1, "ProtectPDF", "Could not find Policy named: """ & strPolicyName & """"
End If
success = oPDDoc.Save(PDSaveFull, strFilePath)
oPDDoc.Close
Else
Err.Raise vbObjectError + 2, "ProtectPDF", "Failed to open " & strFilePath
End If
Exit Sub
ErrHandler:
'Handle any Adobe errors here...
End Sub