cyb*_*do0 8 pdf microsoft-office autohotkey context-menu conversion
我正在寻找一种能够在 Windows 7 中向右键单击上下文菜单添加一些选项的方法。我在编程方面确实没有太多经验,但我非常渴望并愿意学习。
具体来说,我希望能够右键单击 word 文档并将其转换或另存为 .PDF 文件。我希望能够将现有文档转换为 PDF 格式。这些文档 99% 的时间都是 Microsoft Word 文档,因此如果有一种方法可以实现自动化,请提供指导。
我知道还有其他方法可以做到这一点,例如下载“PDF 打印机”,但如果可以,我宁愿避免使用这种方法。如果可能的话,我还想避免下载更多软件以安装在用户的 PC 上。
希望我不是很苛刻,但我真的很感激你能提供的任何帮助或指导。
(作为奖励,我想看看是否还可以选择另存为 PDF 并在可能的情况下作为附件发送。)
小智 8
这是Word 2013的解决方案。它只涉及向Word添加Visual Basic宏和向注册表添加少量记录。
在 Word 2013 中创建全局宏:在 Word 中打开任意文档,打开内置的 Visual Basic 编辑器(Alt + F11),在左侧面板中选择Normal,在主菜单中单击Insert,然后单击Module,将代码复制到编辑:
Sub ExportToPDFext()
ChangeFileOpenDirectory ThisDocument.Path
ActiveDocument.ExportAsFixedFormat _
OutputFileName:=Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, ".")) + "pdf", _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
From:=1, _
To:=1, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=False
Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub
Run Code Online (Sandbox Code Playgroud)
保存模块 (Ctrl + S) 并关闭 Visual Basic 编辑器和 Word。
然后将上下文菜单选项添加到注册表。创建并执行扩展名为 的文件.reg:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere]
@="Save PDF here"
[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""
[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere]
@="Save PDF here"
[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""
Run Code Online (Sandbox Code Playgroud)
右键单击“在此处保存 PDF”将出现在资源管理器中,用于 DOC 和 DOCX 文件。
它静默运行并支持多个选定文档的批量转换。
我很抱歉忘记了这个问题,但至少我终于回答了这个问题,对吧?
我找不到一种方法来按照我想要的方式完成此任务,所以我做了一个小小的解决方法。我创建并编译了 2 个单独的 .ahk ( AutoHotkey ) 脚本,并将它们添加到右键单击上下文菜单中。
以下是脚本:
; AutoHotkey Script by Cyborg v1.5
; This script is designed to be compiled and ran in the user's Send To Right-Click Menu.
; The user needs to right click a word document go into the send to menu and choose this
; script. After launching the script the selected file will open in its version of Word
; and open the menus to save it as a PDF. In this version the user is unable to rename the
; the file.
; NOTE: In order for this to work correctly with Office 2007 you MUST have already installed
; the PDF/XPS converter from Microsoft.
SetTitleMatchMode 2
Loop %0%
{
Path := %A_Index%
Run,% Path
}
IfWinExist, Microsoft Word
WinActivate
sleep 1000
Word2007:
IfExist, C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE ; Microsoft Word 2007
{
Send ^s
Send !f
Send f
Send p
Sleep 500
Send {Enter}
Sleep 500
WinClose, Microsoft Word
}
else
{
Goto, Word2010
}
return
Word2010:
IfExist, C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE ; Microsoft Word 2010
{
Send ^s
Send !f
Send d
Send p
Send a
Sleep 500
Send {Enter}
Sleep 500
WinClose, Microsoft Word
}
else
{
Goto, Word2013
}
return
Run Code Online (Sandbox Code Playgroud)
; AutoHotkey Script by Cyborg v1.5
; This script is designed to be compiled and ran in the user's Send To Right-Click Menu.
; The user needs to right click a word document go into the send to menu and choose this
; script. After launching the script the selected file will open in its version of Excel
; and open the menus to save it as a PDF. In this version the user is unable to rename the
; the file.
; NOTE: In order for this to work correctly with Office 2007 you MUST have already installed
; the PDF/XPS converter from Microsoft.
SetTitleMatchMode 2
Loop %0%
{
Path := %A_Index%
Run,% Path
}
IfWinExist, Microsoft Excel
WinActivate
sleep 1500
Excel2007:
IfExist, C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE ; Microsoft Excel 2007
{
Send ^s
Send !f
Send f
Send p
Sleep 700
Send {Enter}
Sleep 700
WinClose, Microsoft Excel
}
else
{
Goto, Excel2010
}
return
Excel2010:
IfExist, C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE ; Microsoft Excel 2010
{
Send ^s
Send !f
Send d
Send p
Send a
Sleep 500
Send {Enter}
Sleep 500
WinClose, Microsoft Excel
}
else
{
Goto, Excel2013
}
return
Excel2013:
MsgBox, Excel 2013 Not Configured for this Script.
return
Run Code Online (Sandbox Code Playgroud)
一旦我编写了这些脚本并将它们编译成 .exe,我就按照 HowToGeek 的指南将它们放入 SendTo 中。
您也许还可以将每个脚本应用于每种文件类型,但我没有对此进行研究。