今天安装了免费的PDF打印机软件PDFCreator,默认情况下弹出保存窗口,依照以下设定,可以自动保存:
但是存在一个问题:如果<Title>存在空格,则保存后的文件名会从第一个空格后断开,.pdf 后缀名也不会被添加。
PDFCreator一个比较好的地方在于支持动作脚本,即保存前后可以执行指定的VBS文件。
依照以下步骤,即可解决之前的问题:
1. 打开记事本,复制以下代码,另存为Rename.wsf至<PDFCreator安装路径>\Scripts\RunProgramAfterSaving目录下;
————————————————————————————————————————————————
<?xml version="1.0" ?>
<package>
<comment>
PrimalCode wizard generated file.
</comment>
<job id="Rename">
<reference id="Scripting.FileSystemObject" guid="{420B2830-E718-11CF-893D-00A0C9054228}" version="1.0"/>
<reference id="MSSHELL" guid="{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}" version="1.0"/>
<reference id="MSXML" guid="{D63E0CE2-A0A2-11D0-9C02-00C04FC99C8E}" version="2.0"/>
<reference id="MSHTML" guid="{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}" version="4.0"/>
<object id="fso" progid="Scripting.FileSystemObject"/>
<object id="WshShell" progid="WScript.Shell"/>
<object id="Net" progid="WScript.Network"/>
<object id="dic" progid="Scripting.Dictionary"/>
<script id="publish_nc" language="VBScript">
<![CDATA[
'
' Primalscript 2007 Windows Script Wizard generated
'
Dim objArgs
Set objArgs = WScript.Arguments
Main()
Sub Main()
If objArgs.Count = 0 Then
MsgBox "This script needs a parameter!", vbExclamation, AppTitle
WScript.Quit
End If
Dim fname0, fname1
fname0 = objArgs(0)
fname1 = fname0
IF GetFileExt(fname0) <> "pdf" Then
fname1 = fname1 & ".pdf"
fso.movefile fname0, fname1
End If
WshShell.Run chr(34) & fname1 & chr(34),0
End Sub
Function GetFileExt(sFileName)
Dim P
For P = Len(sFileName) To 1 Step -1
If InStr(".", Mid(sFileName, P, 1)) Then Exit For
Next
GetFileExt = Right(sFileName, Len(sFileName) - P)
End Function
]]>
</script>
</job>
</package>
————————————————————————————————————————————————
2. 勾选“保存后动作”,下拉框中选择Rename.wsf,保存。
OK了^o^