Windows 7批处理命令行保存为word 2013 .docx文件的.pdf文件


8

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

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

File -> Save as -> Browse for location

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


Answers:


10

在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

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

"C:\Program Files\Microsoft Office\Office15\WINWORD.EXE" /mExportToPDFext /q "your_document_path.docx"

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\"" 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.