用于检查多个PDF文档的所有页面中的水印的脚本

时间:2017-11-19 03:52:47

标签: adobe acrobat

我有大量的PDF文档,他们正在手动检查所有页面中的水印。是否可以通过脚本实现自动化。每个页面只包含一个水印。最好还是返回所有页面中没有水印的文件名或文档列表。

1 个答案:

答案 0 :(得分:0)

pdf中的水印将存储在OCG对象中。因此,您必须询问acrobat此对象是否在pdf中以及是否保留水印。

附上你会找到可以做到这一点的VBS / VBA代码。您可以将代码复制到记事本,然后将其保存为" FindWatermarks.vbs"在桌面上。然后拖放一些pdf,脚本会告诉你pdf是否包含水印。祝你好运,莱因哈德

PS。:该脚本仅适用于Adobe Acrobat $$$版本,而不仅适用于Reader!

    '// test dropped files for included watermarks
set WshShell = CreateObject ("Wscript.Shell")
set fs = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
    '// check if files has been dropped on the script
if objArgs.Count < 1 then
        msgbox("Please drag a file on the script")
        WScript.quit
    else
        msgbox("Files Count: "& objArgs.Count &vblf &"Start with file: " & ObjArgs(0))
end if
    '//contact Acrobat
Set App = CreateObject("AcroExch.App")
App.show 'comment or take out to work in hidden mode
Set AVDoc = CreateObject("AcroExch.AVDoc")
Set AForm = CreateObject("AFormAut.App") 'from AFormAPI
    '// write needed js code into vbs variable
js  = "var found "&vblf _
    & "var ocgArray = this.getOCGs();" &vblf _
    & "if (ocgArray == null) {      " &vblf _
    & " found = 0;                  " &vblf _
    & " }else{                      " &vblf _
    & " for (var i=0; i < ocgArray.length; i++) {   " &vblf _
    & "     if (ocgArray[i].name == 'Watermark') {  " &vblf _
    & "         found= 1;           " &vblf _
    & "     }else{                  " &vblf _
    & "         found = 0;          " &vblf _
    & "     }                       " &vblf _
    & " }                           " &vblf _
    & " }"

filesWithWm = ""
filesExWm =""
    '//open files via Avdoc and check for watermarks
for i=0 to objArgs.Count - 1
    FileIn = ObjArgs(i)
    If AVDoc.Open(FileIn, "") Then
        'msgbox(FileIn)
        Set PDDoc = AVDoc.GetPDDoc()
        Set jso = PDDoc.GetJSObject
        AForm.Fields.ExecuteThisJavaScript js
        if jso.found = 1 then
            filesWithWm = filesWithWm &FileIn &vblf
        else
            filesExWm = filesExWm &FileIn &vblf
        end if

    end if
next
    '// report found files
if InStr(filesWithWm,":\")>0 then msgbox("Watermarks found:" &vblf & filesWithWm)
if InStr(filesExWm,":\")>0 then msgbox("No Watermarks found:" &vblf & filesExWm)
    '// exit application
App.CloseAllDocs
App.Exit

Set AForm = Nothing
Set JSO = Nothing
Set PDDoc = Nothing
Set AVDoc = Nothing
Set App = Nothing

如果您需要更改代码,请与我们联系。