Word 2013 .docx 파일을 .pdf 파일로 저장하는 Windows 7 배치 명령줄

Word 2013 .docx 파일을 .pdf 파일로 저장하는 Windows 7 배치 명령줄

보고서를 내보내는 가장 빠른 방법을 알고 싶습니다..docx파일을 제출하다.pdf새로운 업데이트 버전이 나올 때마다 다른 사람들에게 배포할 수도 있습니다.

지금까지 마우스를 사용하여 수동으로 수행해야 했던 다음 단계를 자동화하는 명령줄 접근 방식을 찾고 있습니다.

File -> Save as -> Browse for location

배치 파일에 대한 명령 옵션은 무엇입니까?

답변1

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\"" 

답변2

일괄 변환을 위한 간단한 명령줄 도구의 경우 다음을 사용할 수 있습니다 docx2pdf.https://github.com/AlJohri/docx2pdf/

설치하다:

pip install docx2pdf

달리다:

docx2pdf myFolderOfWordDocs

면책조항: 저는 이 도구의 작성자입니다.

답변3

해결책은 다음과 같습니다.올렉시 코프툰현재 Office 16(Office 360)으로 채택되었습니다.

Word 매크로 ThisDocument.Path에서 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

레지스트리의 경우 Office 16은 약간 다른 경로를 사용합니다.

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\""

관련 정보