Windows 7 批处理命令行将 Word 2013 .docx 文件另存为 .pdf 文件

Nam*_* VU 11 pdf batch command-line batch-file microsoft-word-2013

我想以最快的方式将我的报告.docx文件导出为.pdf并在我有新的更新版本时将其分发给其他人。

我正在寻找一种命令行方法,可以自动执行到目前为止我必须使用鼠标手动执行的以下步骤:

File -> Save as -> Browse for location
Run Code Online (Sandbox Code Playgroud)

批处理文件的命令选项是什么?

小智 12

在 Word 2013 中创建全局宏:

' The Word macro for exporting to PDF (the Word window closes after finishing)
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)

之后,您可以在命令行中将 Word 文档转换为 PDF:

"C:\Program Files\Microsoft Office\Office15\WINWORD.EXE" /mExportToPDFext /q "your_document_path.docx"
Run Code Online (Sandbox Code Playgroud)

Word 窗口甚至不会显示,因为它被设置为在宏完成工作后关闭,并且参数 /q 在 Word 加载时禁用启动窗口。

以下是GitHub 上的替代详细说明。此外,即使没有命令行,上下文菜单选项也允许批量转换。它可以添加到注册表中。对于 DOC 和 DOCX:

[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)


归档时间:

查看次数:

16313 次

最近记录:

4 年,2 月 前