使用 Acrobat.tlb 参考我试图检查PDF文件是否受到保护/是否设置了任何限制。 我检查了Acrobat JavaScript Scripting Reference,但我做错了:
Sub CheckPDFsecurity()
Dim oPDDoc As Acrobat.AcroPDDoc
Dim oPapp As Acrobat.AcroApp
Dim oJso As Object
Dim oSec As Object
Dim arrPolicies As Variant
Dim i As Integer
Set oPapp = CreateObject("AcroExch.App")
oPapp.MenuItemExecute ("COMP:AddBack")
Set oPDDoc = CreateObject("AcroExch.PDDoc")
oPDDoc.Open ("D:\test\test2.pdf")
Set oJso = oPDDoc.GetJSObject
Set oSec = oJso.security
arrPolicies = oJso.getLegalWarnings(True)
For i = 0 To UBound(arrPolicies)
MsgBox (arrPolicies(i))
Next i
oPDDoc.Close
Set oPDDoc = Nothing
End Sub
请有人这么友善,帮助我正确检查PDF文件的安全设置。 谢谢!
答案 0 :(得分:1)
好的,我找到了方法。也许它不是最好的,但至少它是有效的,它提供信息,如果PDF是安全的。
Sub CheckPDFsecurity()
On Error GoTo NoSecurity
Dim oPDDoc As Acrobat.AcroPDDoc
Dim oPapp As Acrobat.AcroApp
Dim oJso As Object
Dim oSec As Object
Dim arrPolicies As String
Set oPapp = CreateObject("AcroExch.App")
Set oPDDoc = CreateObject("AcroExch.PDDoc")
oPDDoc.Open ("D:\test\test1.pdf")
Set oJso = oPDDoc.GetJSObject
Set oSec = oJso.app.openDoc(cPath:="D:\test\test1.pdf", bHidden:=True)
If oSec.securityHandler = vbNullString Then
NoSecurity:
arrPolicies = "No Security"
Else
arrPolicies = oSec.securityHandler
End If
MsgBox (arrPolicies)
oSec.CloseDoc
oPDDoc.Close
Set oPDDoc = Nothing
oPapp.Exit
End Sub