Windows 7-Batch-Befehlszeile zum Speichern als PDF-Datei für Word 2013-DOCX-Datei

Windows 7-Batch-Befehlszeile zum Speichern als PDF-Datei für Word 2013-DOCX-Datei

Ich möchte meinen Bericht am schnellsten exportieren.docxDatei in.pdfund verteile es an andere, sobald ich eine neue, aktualisierte Version habe.

Ich suche nach einem Befehlszeilen-Ansatz, der die folgenden Schritte automatisiert, die ich bisher manuell mit meiner Maus ausführen muss:

File -> Save as -> Browse for location

Welche Befehlsoptionen habe ich für eine Batchdatei?

Antwort1

Erstellen Sie ein globales Makro in 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

Anschließend können Sie ein Word-Dokument in der Befehlszeile in PDF konvertieren:

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

Das Word-Fenster wird nicht einmal angezeigt, da es so eingestellt ist, dass es geschlossen wird, nachdem das Makro fertig ist, und der Parameter /q deaktiviert das Splash-Fenster während des Ladens von Word.

Hier die alternative ausführliche Anleitungauf GitHub. Außerdem ermöglicht die Kontextmenüoption die Stapelkonvertierung auch ohne Befehlszeile. Sie kann zur Registrierung hinzugefügt werden. Für DOC und 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\"" 

Antwort2

Als einfaches Befehlszeilentool zur Stapelkonvertierung können Sie Folgendes verwenden docx2pdf:https://github.com/AlJohri/docx2pdf/

Installieren:

pip install docx2pdf

Laufen:

docx2pdf myFolderOfWordDocs

Haftungsausschluss: Ich bin der Autor dieses Tools.

Antwort3

Hier ist die Lösung vonOleksiy Kovtunan das aktuelle Office 16 (Office 360) angepasst.

Im Word-Makro musste ich es ThisDocument.Pathin ändern ActiveDocument.Path.

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

Für das Standesamt 16 werden leicht abweichende Pfade verwendet:

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\\root\\Office16\\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\\root\\Office16\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""

verwandte Informationen