测试环境:
Acrobat Professional 10.1
Acrobat Read 8.3
AutoIt v3.3.6.1
有很多pdf文件要变成Acrobat reader可以Commenting的,Acrobat professional没提供javascript等接口实现批量处理,所以只好用AutoIt实现自动转换了。
另外,如果从IE中调用Acrobat Reader读取PDF进行Commenting,Commenting工具条不能显示,这时可以通过Acrobat Professional的批量处理,把下面的JavaScript加入pdf:
- /* Acrobat Professional has a "Batch Processing" Option and you can "Run a JavaScript" as one of the processing options, you only need to add the script to insert a document level JavaScript. */
- this.addScript("CallabSet", 'Collab.showAnnotToolsWhenNoCollab = true;');
下面是AutoIt代码:
- BlockInput(1)
- #include <File.au3>
- #Include <Date.au3>
- $workdir = "e:\pdfs\"
- $listfile = $workdir & "list.txt"
- $logfile = $workdir & "log.txt"
- Dim $pdfs[10000]
- $acrobatprogram = 'C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe'
- $acrobat = "Adobe Acrobat Pro"
- $conn = " - "
- $totalfiles = _FileCountLines($listfile)
- if $totalfiles = 0 Then
- MsgBox(0, "autoit","no list file")
- Exit
- endIf
- $fl = FileOpen($listfile, 0)
- for $i = 1 to $totalfiles
- $pdfs[$i] = FileReadLine($fl, $i)
- Next
- FileClose($fl)
- Opt("MouseCoordMode", 0) ;1=绝对坐标,相对屏幕, 0=相对坐标,相对当前激活窗体
- $log = FileOpen($logfile, 1)
- FileWriteLine ($log, "Total " & $totalfiles & " files to be processed")
- FileWriteLine ($log, "Started at " & _NowDate() & " " & _NowTime())
- Run($acrobatprogram)
- For $i = 1 To $totalfiles
- ;MsgBox(1,2,$pdfs[$i])
- if $pdfs[$i] = "" Then
- ContinueLoop
- EndIf
- $temp = $pdfs[$i] & $conn & $acrobat
- _WinWaitActivate($acrobat,"")
- Send("^o")
- _WinWaitActivate("打开","")
- Send($workdir & $pdfs[$i])
- ControlClick ("打开", "Open", "Button2")
- _WinWaitActivate($temp,"")
- MouseClick("left",20,40,1)
- WinWait("","",1)
- MouseClick("left",20,140,1)
- WinWait("","",1)
- MouseClick("left",410,210,1)
- WinWait("","",1)
- MouseClick("left",580,230,1)
- _WinWaitActivate("Save As","")
- ControlClick ("Save As", "", "Button2")
- WinWait("","",1)
- ControlClick ("Save As", "", "Button1")
- ;_WinWaitActivate($temp,"", 2)
- WinWaitActive($temp)
- Send("^w")
- FileWriteLine($log, $pdfs[$i])
- FileFlush($log)
- Next
- _WinWaitActivate($acrobat,"")
- Send("^q")
- BlockInput(0)
- FileWriteLine ($log, "Stoped at " & _NowDate() & " " & _NowTime())
- FileClose($log)
- Func _WinWaitActivate($title,$text,$timeout=0)
- WinWait($title,$text,$timeout)
- If Not WinActive($title,$text) Then WinActivate($title,$text)
- WinWaitActive($title,$text)
- EndFunc
Adobe reader隐藏菜单和工具栏,把下面的javascript保存成文件hidefunction.js,放到下面目录中:
C:\Program Files\Adobe\Acrobat 8.0\Reader\JavaScripts
- disclosed = true;
- var sPlatform = app.viewerVariation;
- var sLogin = identity.loginName;
- var sPos = "5";
- if (sPlatform == "Reader") {
- sPos = "5";
- }
- if (sPlatform == "Fill-In") {
- sPos = "5";
- }
- if (sPlatform == "Full") {
- sPos = "7";
- }
- //HIDE MENU ITEMS
- app.hideMenuItem("SaveAs");
- app.hideMenu("All");
- //HIDE TOOLBARBUTTONS
- app.hideToolbarButton("Save");
- //DETERMINE THE USER LEVEL OF CONTROL
- var sTemp = sLogin.toUpperCase();
- switch (sTemp) {
- case 'ROBDOG888' :
- app.alert('Full Control Allowed To User: ' + sTemp,3,0);
- default :
- app.alert('Controlled Access Only!',3,0);
- }